don't print results of a function

一曲冷凌霜 提交于 2019-12-12 01:09:54

问题


I am using python and pybrain for Neural Networks. Unfortunately, my sample is realy big and when the program print the errors on the training, my memory get full before the programm completed.

Is there anyway to not print the errors from the functions?

!!!! It's not a python error. It's pybrain feature. It's print the difference of the prediction and the real sample. For example "error: 0.00424".

Each time it makes a prediction, it print this string.

Here is my code

ds = SupervisedDataSet(1, 1)
ds.addSample(x,y) <--- in a "for" to add all my sample

net = FeedForwardNetwork() 
inp = LinearLayer(1) 
h1 = SigmoidLayer(1) 
outp = LinearLayer(1)

net.addOutputModule(outp) 
net.addInputModule(inp) 
net.addModule(h1)

net.addConnection(FullConnection(inp, h1))  
net.addConnection(FullConnection(h1, outp))

net.sortModules()

trainer = BackpropTrainer(net, ds)

trainer.trainOnDataset(ds)      ###
trainer.testOnData(verbose=True)### Here is where the function print the errors

net.activate((ind,))

回答1:


You could use try/except, like this:

try:
    trainer.testOnData(verbose=True)
except Exception as e:
    <exception handling code>

or you could find the source of the error. Could you add the error you get to your question?



来源:https://stackoverflow.com/questions/16962274/dont-print-results-of-a-function

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!