當前位置: 首頁>>代碼示例>>Python>>正文


Python RBM.encode方法代碼示例

本文整理匯總了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'))
開發者ID:BenedicteLC,項目名稱:Sparse_Project,代碼行數:57,代碼來源:get_rbm_rep.py


注:本文中的rbm.RBM.encode方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。