2014-07-10 81 views
18

我在使用Pybrain訓練DBN時遇到一些困難。 首先,我試圖做的簡單的方法:PyBrain - 如何做深層信仰網絡培訓?

net = buildNetwork(*layerDims) 

我面臨這個問題:How to do supervised deepbelief training in PyBrain?和建議的解決方案只是導致了另一個錯誤:

File "/home/WORK/Canopy_64bit/User/lib/python2.7/site-packages/PyBrain-0.3.1- py2.7.egg/pybrain/unsupervised/trainers/deepbelief.py", line 62, in <genexpr> 
layercons = (self.net.connections[i][0] for i in layers) 
IndexError: list index out of range 

於是,我就確定從網絡刮!

inp = LinearLayer(3 , 'visible') 
hidden0 = SigmoidLayer(2 , 'hidden0') 
hidden1= SigmoidLayer(2 , 'hidden1') 
output = LinearLayer(2 , 'output') 
bias = BiasUnit('bias') 
net = Network() 
net.addInputModule(inp) 
net.addModule(hidden0) 
net.addModule(hidden1) 
net.addModule(output) 
net.addModule(bias) 
net.addConnection(FullConnection(inp, hidden0)) 
net.addConnection(FullConnection(hidden0, hidden1)) 
net.addConnection(FullConnection(hidden1, output)) 
net.addConnection(FullConnection(bias, hidden0)) 
net.addConnection(FullConnection(bias, hidden1)) 
net.addConnection(FullConnection(bias, output)) 
net.sortModules() 

仍然當我運行:

trainer = deepbelief.DeepBeliefTrainer(net1, dataset=ds) 
trainer.trainEpochs(epochs) 

我看到這個錯誤:

File "/home/WORK/Canopy_64bit/User/lib/python2.7/site-packages/PyBrain-0.3.1-py2.7.egg/pybrain/structure/connections/connection.py", line 37, in __init__ 
self.outSliceTo = outmod.indim 
AttributeError: 'NoneType' object has no attribute 'indim' 

其中有事情做與相關RBM隱藏層。

我在這裏錯過了什麼嗎?

+1

您需要製作一個輸出模塊。所以addModule(輸出)應該是addOutputModule(輸出)。 – jay

+3

Pybrain是非常緩慢的圖書館。我轉移到了caffe或c庫等其他庫,這些庫的速度提高了25倍甚至更多。 – pbu

+1

而不是這個舊圖書館,我建議看一個[Theano](http://deeplearning.net/software/theano/)爲基礎的庫,如[Blocks](https://github.com/mila-udem/)塊)。 –

回答

1

你的名字net下初始化網絡:

net = Network() 
net.addInputModule(inp) 
net.addModule(hidden0) 
net.addModule(hidden1) 
net.addModule(output) 
net.addModule(bias) 
net.addConnection(FullConnection(inp, hidden0)) 
net.addConnection(FullConnection(hidden0, hidden1)) 
net.addConnection(FullConnection(hidden1, output)) 
net.addConnection(FullConnection(bias, hidden0)) 
net.addConnection(FullConnection(bias, hidden1)) 
net.addConnection(FullConnection(bias, output)) 
net.sortModules() 

但你傳遞作爲參數net1

trainer = deepbelief.DeepBeliefTrainer(net1, dataset=ds) 
trainer.trainEpochs(epochs) 

這將導致一個錯誤是肯定的。

所以

trainer = deepbelief.DeepBeliefTrainer(net, dataset=ds) 

應該解決您的問題。