Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to save a Trainer? #227

Open
aiLiwensong opened this issue Nov 2, 2017 · 2 comments
Open

How to save a Trainer? #227

aiLiwensong opened this issue Nov 2, 2017 · 2 comments

Comments

@aiLiwensong
Copy link

aiLiwensong commented Nov 2, 2017

Now, I have trained my DIY net. How can I save it, so that I can use it again sometimes?

trainer = BackpropTrainer(fnn,dataset=trndata,verbose=True)

save up trainer.

@NuclearManD
Copy link

I would use pickle. Although I have only lightly used PyBrain, pickle should almost always work. I have an example with your code:
import pickle
(rest of your imports and code before pickling)
trainer = BackpropTrainer(fnn,dataset=trndata,verbose=True)
f=open("your_file.pd",'wb')
pickle.dump(trainer,f)
f.close()
This will save your trainer. To load it:
import pickle,BackpropTrainer
f=open("your_file.pd",'rb')
trainer=pickle.load(f)
f.close()
In order to load the trainer the BackpropTrainer will have to be imported before unpickling. I haven't tested this code, but it should work.

Note that the "pickle module is not secure against erroneous or maliciously constructed data."(Python Docs)
If you are only saving it for yourself it's fine, but be careful otherwise. See the Python Docs or SO

Of course, it would be very nice to have a serialization exclusively for your trainer, but I have only lightly used Pybrain and know of no serialization. Pickle is what I would use for most of the code I write.

@aiLiwensong
Copy link
Author

Thanks for your answer. I'll try! @NuclearManD

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants