lmjohns3 / theanets

Neural network toolkit for Python
http://theanets.rtfd.org
MIT License
328 stars 74 forks source link

Unable to load a theanets.Regressor from file using the load #114

Closed SadatAnwar closed 8 years ago

SadatAnwar commented 8 years ago

Hey, Sorry if this is a noob question, but I tried using the save function in the theanets.Regressor after I finish training my network, everything goes well, the network is saved and I can even load it, no troubles there, but when I try to use the loaded network, its just off. I even tried loading the network in the same python script, but its still off. The fun thing is if you look at graphs, you see there is a pattern, just a couple of times higher. I also used the debug to look into the network before its written and after its loaded, and there is a difference in the weights.

theanets.__version__
'0.8.0pre'

Here is what I did: This works, but is almost useless screen shot 2015-12-29 at 10 51 09 pm

net = theanets.Regressor(layers=[lags, (hidden, 'sigmoid'), 1], loss='mse')
inputs, targets = prepareTrainingDatasets(TS, lags)

net.train([inputs, targets], algo='sgd', patience=10, max_updates=5000, learning_rate=0.01,         min_improvement=0.001,
      momentum=0.2)
# save the network status
net.save('trained_jan.gz')

net.load('trained_jan.gz')
net.predict([inputs])

This doen't work (this is what I expect to work) screen shot 2015-12-29 at 10 50 03 pm :

net1 = theanets.Regressor(layers=[lags, (hidden, 'sigmoid'), 1], loss='mse')
inputs, targets = prepareTrainingDatasets(TS, lags)

net1.train([inputs, targets], algo='sgd', patience=10, max_updates=5000, learning_rate=0.01,         min_improvement=0.001,
      momentum=0.2)
# save the network status
net1.save('trained_jan.gz')
net1 = None
net = theanets.Regressor(layers=[lags, (hidden, 'sigmoid'), 1], loss='mse')
net.load('trained_jan.gz')
net.predict([inputs])

Any help? BTW love your work! Its amazing!

SadatAnwar commented 8 years ago

Okay now I just feel stupid! I did use the net.load() but I did not assign it to the net object!! AAAAA!! Just proves that its not always fun working till very late in the night!!

Stupid me! Once again, thanks for your amazing work!

lmjohns3 commented 8 years ago

Excellent, glad you noticed the loaded net wasn't being used. Otherwise would definitely have been a bug!