Pybrain:运行时错误

时间:2016-03-13 18:26:55

标签: python pybrain

我正在尝试使用pybrain创建神经网络。 以下是我的代码。

输入神经元的数量是2500。 输出神经元的数量是212。 隐藏神经元的数量是(2500 + 212)/ 2 = 1356。

我的代码:

#for training using the data set
#import built in json module for reading the binary list of lists
import json

#retrieve the input file
f = open('input.txt', 'r')
inputSet = json.load(f) 

#retrieve target file target file
f = open('target.txt', 'r')
targetSet = json.load(f)

#Width and height of character image
w,h = 50, 50

#import pybrain modules
from pybrain.structure.networks import FeedForwardNetwork
from pybrain.datasets import SupervisedDataSet
from pybrain.utilities import percentError
from pybrain.tools.shortcuts import buildNetwork
from pybrain.supervised.trainers import BackpropTrainer
from pybrain.structure.modules import SoftmaxLayer
from pybrain.structure.modules import LinearLayer
from pybrain.structure.modules import SigmoidLayer
from pybrain.structure.modules import TanhLayer
from pybrain.structure.connections import FullConnection
from pybrain.tools.customxml.networkwriter import NetworkWriter
from pybrain.tools.customxml.networkreader import NetworkReader

#import matplotlib to plot the learning graph
import matplotlib.pyplot as plt

#setting up the network
#initialize the number of neurons for the various layers
inputNeurons = w * h #2500
outputNeurons = 212
hiddenNeurons = int((inputNeurons + outputNeurons) /2) #1356

net = buildNetwork(inputNeurons, hiddenNeurons, outputNeurons, bias = True, hiddenclass = SigmoidLayer)

#view a glimpse of NN structure
print net

#initialise dataset
ds = SupervisedDataSet(inputNeurons, outputNeurons)

#add training data to network
for i in range(0,212):
    ds.addSample(inputSet[i], targetSet[i])

#print len(ds)

#initialize trainers
trainer = BackpropTrainer(net, dataset=ds,  learningrate = 0.01, momentum = 0.5, verbose=True)

#startTraining
trainer.trainEpochs (100)

#store network in XML
NetworkWriter.writeToFile(net, 'trained.xml')

问题是对于0.9以外的每个动量值都会遇到以下错误。

Warning (from warnings module):
  File "C:\Python27\lib\site-packages\pybrain-0.3.1-py2.7.egg\pybrain\supervised\trainers\backprop.py", line 97
    error += 0.5 * sum(outerr ** 2)
RuntimeWarning: overflow encountered in square

Warning (from warnings module):
  File "C:\Python27\lib\site-packages\pybrain-0.3.1-py2.7.egg\pybrain\structure\modules\sigmoidlayer.py", line 14
    inerr[:] = outbuf * (1 - outbuf) * outerr
RuntimeWarning: invalid value encountered in multiply

我经常搜索,但无法找到具体的解决方案。

我可以看到它必须用numpy做一些不处理大浮点数但我真的不确定如何修复它。

欢迎任何建议。

0 个答案:

没有答案