本文整理匯總了Python中rbm.RBM.encode方法的典型用法代碼示例。如果您正苦於以下問題:Python RBM.encode方法的具體用法?Python RBM.encode怎麽用?Python RBM.encode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類rbm.RBM
的用法示例。
在下文中一共展示了RBM.encode方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: get_representation
# 需要導入模塊: from rbm import RBM [as 別名]
# 或者: from rbm.RBM import encode [as 別名]
def get_representation():
# Load the dictionary and corresponding args.
(W, b, hidden_size) = pickle.load(open("Models/RBM/model%d.pkl"%experiment_number,'rb'))
# Set the constructor
myObject = RBM(hidden_size=hidden_size)
print "Loading dataset..."
trainset,validset,testset = dataset_store.get_classification_problem('ocr_letters')
encoded_trainset = []
encoded_validset = []
encoded_testset = []
print "Initializing..."
myObject.initialize(W,b)
print "Encoding the trainset..."
counter = 0 #Inelegant, I know! I use this to only use the first 1000 values.
for input,target in trainset:
#Encode the sample.
h = myObject.encode(input)
encoded_trainset.append(h)
# counter +=1
# if counter == 1000:
# break
# Save the datasets to files.
filename = "Models/RBM/trainset%d.pkl"%(experiment_number)
pickle.dump( np.asarray(encoded_trainset) , open(filename, 'wb'))
counter = 0
print "Encoding the validset..."
for input,target in validset:
#Encode the sample.
h = myObject.encode(input)
encoded_validset.append(h)
# counter +=1
# if counter == 1000:
# break
filename = "Models/RBM/validset%d.pkl"%(experiment_number)
pickle.dump( np.asarray(encoded_validset) , open(filename, 'wb'))
#Note: only need to do it for the best hyper-params at the end.
print "Encoding the testset..."
for input,target in testset:
#Encode the sample.
h = myObject.encode(input)
encoded_testset.append(h)
filename = "Models/RBM/testset%d.pkl"%(experiment_number)
pickle.dump( np.asarray(encoded_testset), open(filename, 'wb'))