DBN程序剖析
最近學習深度學習,學習時間半月不到,很多程序似懂非懂,用的又是不太明白的python。不過不怕。什么也難不倒無產階級,自己剖析下,不指望指點別人,只希望高人能指點。
主函數大體可以分為 建立DBN網絡,預訓練模型和微調模型三部分。
1.建立DBN網絡
由class DBN(object)的__init__函數來完成,思路是由前面的隱含層生成后面的隱含層,并生成與每一個隱含層對應的RBM層
2.預訓練模型
首先獲得預訓練函數,由class DBN(object)的pretraining_functions函數來完成,訓練的對象是RBM層.里面的核心語句為
?cost, updates = rbm.get_cost_updates(learning_rate,persistent=None, k=k)
?fn = theano.function(inputs=[index,theano.Param(learning_rate, default=0.1)], outputs=cost,updates=updates,givens={self.x:train_set_x[batch_begin:batch_end]})
第二句的輸出是cost和updates ,要看清他們的結構還得從第一句的RBM的get_cost_updates函數來看。
get_cost_updates是執行一步CD/PCD運算。
?
?
程序首先建立一個類class DBN(object),里面包含3個函數:
1.?def __init__(self, numpy_rng, theano_rng=None, n_ins=784,? hidden_layers_sizes=[500, 500], n_outs=10):
self.n_layers = len(hidden_layers_sizes) 結果為2,表示2層
if not theano_rng:
??????????? theano_rng = RandomStreams(numpy_rng.randint(2 ** 30))
theano_rng說是隨機產生器,不知道做什么用,往下看。
self.x = T.matrix('x')? # the data is presented as rasterized images 數據是光柵化的圖像,是不是可以理解為采樣的圖像
self.y = T.ivector('y')? # the labels are presented as 1D vector
???????????????????????????????? # of [int] labels
下面的代碼對于每一層進行掃描
? for i in xrange(self.n_layers):
??????????? 指定輸入大小:第一層的時候輸入是圖像,否則就是對應隱含層
?????????? 指定輸入層。
???????? 根據? 輸入和輸出層大小、輸入圖像 就可以求出隱含層
???????? 根據隱含層可以求出RBM層
??????????
轉載于:https://www.cnblogs.com/Iknowyou/p/3656153.html
總結
- 上一篇: 【转载】徐小平techCrunch演讲:
- 下一篇: IIS解决 上传文件大小限制