本文整理汇总了Python中rbm.RBM.initialize方法的典型用法代码示例。如果您正苦于以下问题:Python RBM.initialize方法的具体用法?Python RBM.initialize怎么用?Python RBM.initialize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rbm.RBM
的用法示例。
在下文中一共展示了RBM.initialize方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_representation
# 需要导入模块: from rbm import RBM [as 别名]
# 或者: from rbm.RBM import initialize [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'))