Export & Import Trained Models with PyBrain

Recently, I used PyBrain, a machine learning library for Python, to build and train neural networks. With PyBrain, it's fairly easy to build a neural network, and you can export the trained model as an xml file. Of course, if you read this, you can reuse the model.

So, this time I will summarize the installation method and writing / loading the model.

1. Install PyBrain

Use pip for installation.

pip install pybrain

2. Export model

Use from pybrain.tools.xml import NetworkWriter.


from pybrain.tools.shortcuts import buildNetwork

# ~Omission(Reading training data, etc.) ~

#Definition of neural network model
network = buildNetwork(64, 19, 2)

# ~Omission (perform training using data)~

#Export the model
NetworkWriter.writeToFile(network, 'model.xml')

This will output a file called model.xml with the settings of the trained model.

3. Load the model

Use from pybrain.tools.xml import Network Reader.

from pybrain.tools.xml import NetworkReader

network = NetworkReader.readFrom('model.xml')

By reading the model.xml output earlier, the trained model can be reproduced.

After that, please recognize it, learn more, or like it.

Recommended Posts

Export & Import Trained Models with PyBrain
Excel, csv import, export with Django
How to export / import Zope zope object installed with Plone-4.1.5-UnifiedInstaller-20120604.tgz
Import tsv with Python
Import vtk with brew python
AWS Lambda with PyTorch [Lambda import]
Server management with Jupyter (1) import