gpt4 book ai didi

python - PyBrain - 如何进行深度信念网络训练?

转载 作者:IT老高 更新时间:2023-10-28 21:05:18 28 4
gpt4 key购买 nike

我在使用 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中的隐藏层有关。

我错过了什么吗?

最佳答案

你用 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)

应该可以解决你的问题。

关于python - PyBrain - 如何进行深度信念网络训练?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24666036/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com