PyBrain - how to do Deep belief network training?
Asked Answered
M

1

18

I have some difficulty training a DBN using Pybrain. First I tried to do it the simple way:

net = buildNetwork(*layerDims)

I faced this problem: How to do supervised deepbelief training in PyBrain? , and the suggested solution just led to another error:

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

So I tried to define a network from scratch!

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()

still when I run:

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

I see this error:

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'

which has something to do with the hidden layer in the related RBM.

Am I missing something here?

Monostylous answered 10/7, 2014 at 1:11 Comment(3)
You need to make an output module. So addModule(output) should be addOutputModule(output).Ferro
Pybrain is extremely slow library. I moved to other libraries such as caffe or c libraries, which are 25X faster or more.Intermittent
Instead of this old library, I suggest looking at a Theano-based library such as Blocks.Wuhu
C
1

You initialize a network under the 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()

But you pass as argument net1:

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

This causes an error for sure.

So

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

should solve your problem.

Convector answered 23/7, 2015 at 10:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.