请帮忙。我一直试图用一个简单的深层神经网络的DeepBeliefTrainer没有成功。我正在使用这里提供的DeepBeliefTrainer:http://tinyurl.com/jeexh5g
我得到以下错误: 文件“…\pybrain\structure\modules”\模块.py“,第104行,激活” 断言len(自输入缓冲区[自补偿])==长度(输入),str((长度(自输入缓冲区[自补偿]),长度(输入))) 断言错误:(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()
非常感谢你的帮助。你知道吗
目前没有回答
相关问题 更多 >
编程相关推荐