PyBrain - 如何做深度信念网络培训?

时间:2014-07-10 01:11:20

标签: python pybrain deep-learning dbn

使用Pybrain训练DBN时遇到一些困难。 首先,我试着用简单的方法做到这一点:

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 个答案:

答案 0 :(得分: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)

应该解决你的问题。