18

我在使用 Pybrain 训练 DBN 时遇到了一些困难。首先,我尝试以简单的方式做到这一点:

net = buildNetwork(*layerDims)

我遇到了这个问题:如何在 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 中的隐藏层有关。

我在这里错过了什么吗?

4

1 回答 1

1

您以 name 初始化网络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)

应该可以解决您的问题。

于 2015-07-23T10:36:02.367 回答