我无法让DeepBeliefTrainer在Pybrain中使用FeedForwardNetwork

时间:2016-02-13 14:02:50

标签: python

请帮忙。我一直试图将DeepBeliefTrainer与简单的深度神经网络一起使用,但没有成功。我在这里使用DeepBeliefTrainer:http://tinyurl.com/jeexh5g

我收到以下错误: 文件" ... \ pybrain \ structure \ modules \ module.py",第104行,激活 断言len(self.inputbuffer [self.offset])== len(inpt),str((len(self.inputbuffer [self.offset]),len(inpt))) AssertionError:(2,1)

以下是我的代码:

ds = SupervisedDataSet(2, 1)
ds.addSample([0,0],[0])
ds.addSample([0,1],[1])
ds.addSample([1,0],[1])
ds.addSample([1,1],[0])

n = FeedForwardNetwork()
no_neurons_hidden_layers = int(round(0.6 * ds.indim))
# creating layers
bias = BiasUnit(name='bias')
inLayer = LinearLayer(ds.indim,name='visible')
hiddenLayer1 = TanhLayer(no_neurons_hidden_layers,name='h1')
hiddenLayer2 = TanhLayer(no_neurons_hidden_layers,name='h2')
hiddenLayer3 = TanhLayer(no_neurons_hidden_layers,name='h3')
outLayer = SoftmaxLayer(ds.outdim,name='out')

# adding layers to modules
n.addInputModule(inLayer)
n.addModule(bias)
n.addModule(hiddenLayer1)
n.addModule(hiddenLayer2)
n.addModule(hiddenLayer3)
n.addOutputModule(outLayer)

# connecting layers to each other
inLayer_to_hidden1 = FullConnection(inLayer, hiddenLayer1)
bias_to_hidden1 = FullConnection(bias, hiddenLayer1)
hidden1_to_hidden2 = FullConnection(hiddenLayer1,hiddenLayer2)
hidden2_to_hidden3 = FullConnection(hiddenLayer2,hiddenLayer3)
hidden3_to_outLayer = FullConnection(hiddenLayer3,outLayer)
bias_to_outLayer = FullConnection(bias, outLayer)

#add connections
n.addConnection(inLayer_to_hidden1)
n.addConnection(bias_to_hidden1)
n.addConnection(hidden1_to_hidden2)
n.addConnection(hidden2_to_hidden3)
n.addConnection(hidden3_to_outLayer)
n.addConnection(bias_to_outLayer)

#sort modules
n.sortModules()

#make a Deep Belief Network
cfg = RbmGibbsTrainerConfig()
cfg.maxIter = 3
dbn = DeepBeliefTrainer(n,ds,epochs=50,cfg=cfg, distribution='bernoulli')
dbn.train()

非常感谢您的帮助。

0 个答案:

没有答案