Persist the neural network built with PyBrain

A story when you want to create a neural network with the machine learning library PyBrain and make it persistent with S3.

Use pickle

Using python's standard serialization module pickle, the neural network seems to be saved and restored, and you can also ʻactivate () for objects that are properly pickle.load () `.

However, I was addicted to the problem that learning by BackpropTrainer.train () etc. was not restarted. The detailed behavior of pickle is unknown, and the cause has not been investigated.

Use NetworkWriter

Using NetworkWriter, which is provided as a utility of PyBrain, solves the above problem and resumes learning. It's easy to use, so I think this is fine.

import

python


from pybrain.tools.customxml import NetworkWriter, NetworkReader

Export

python


NetworkWriter.writeToFile(network, filename_local)

Read

python


network = NetworkReader.readFrom(filename_local)

The file is saved in XML, and I can understand that it is doing neural network, and it is somewhat more secure than the pickle format.

python


<?xml version="1.0" ?>
<PyBrain>
        <Network class="pybrain.structure.networks.feedforward.FeedForwardNetwork" name="FeedForwardNetwork-8">
                <name val="u'FeedForwardNetwork-8'"/>
                <Modules>
                        <LinearLayer class="pybrain.structure.modules.linearlayer.LinearLayer" inmodule="True" name="in">
                                <dim val="8"/>
                                <name val="'in'"/>
                        </LinearLayer>
                        <LinearLayer class="pybrain.structure.modules.linearlayer.LinearLayer" name="out" outmodule="True">
                                <dim val="1"/>
                                <name val="'out'"/>
                        </LinearLayer>
                        <BiasUnit class="pybrain.structure.modules.biasunit.BiasUnit" name="bias">
                                <name val="'bias'"/>
                        </BiasUnit>
                        <SigmoidLayer class="pybrain.structure.modules.sigmoidlayer.SigmoidLayer" name="hidden0">
                                <dim val="3"/>
                                <name val="'hidden0'"/>
                        </SigmoidLayer>
                </Modules>
                <Connections>
                        <FullConnection class="pybrain.structure.connections.full.FullConnection" name="FullConnection-6">
                                <inmod val="bias"/>
                                <outmod val="out"/>
                                <Parameters>[0.6554487520957738]</Parameters>
                        </FullConnection>
                        <FullConnection class="pybrain.structure.connections.full.FullConnection" name="FullConnection-7">
                                <inmod val="bias"/>
                                <outmod val="hidden0"/>
                                <Parameters>[0.8141201069100833, -1.9519540651889176, 0.3483014480876096]</Parameters>
                        </FullConnection>
                        <FullConnection class="pybrain.structure.connections.full.FullConnection" name="FullConnection-5">
                                <inmod val="in"/>
                                <outmod val="hidden0"/>
                                <Parameters>[0.32489279837910084, 0.34480786433574551, 0.75045803824057666, -0.58411948692771176, -0.12327324616272992, -0.41228675759787226, -0.85553671683893218, -1.3320521945223582, -1.0531422952418676, -0.40839301403900452, -2.7565756871565674, -1.6723188687051469, -1.3597994054921079, 0.24852450267525059, -0.40924881241151689, 0.54037857219934371, 1.0960673042273468, 1.3324258379470664, 0.29047259837334116, -0.022417631256966383, 0.44571376571760984, 0.6492450404233816, -0.29105564158278247, 1.2243353023571237]</Parameters>
                        </FullConnection>
                        <FullConnection class="pybrain.structure.connections.full.FullConnection" name="FullConnection-4">
                                <inmod val="hidden0"/>
                                <outmod val="out"/>
                                <Parameters>[0.25616738836523284, -2.2028123481048487, -0.11026881677981226]</Parameters>
                        </FullConnection>
                </Connections>
        </Network>
</PyBrain>

Recommended Posts

Persist the neural network built with PyBrain
Neural network with Python (scikit-learn)
3. Normal distribution with neural network!
Neural network starting with Chainer
4. Circle parameters with neural network!
Neural network with OpenCV 3 and Python 3
Simple classification model with neural network
[TensorFlow] [Keras] Neural network construction with Keras
Touch the object of the neural network
Compose with a neural network! Run Magenta
Predict time series data with neural network
2. Mean and standard deviation with neural network!
Load the network modeled with Rhinoceros in Python ③
Experiment with various optimization algorithms with a neural network
Visualize the inner layer of a neural network
Verification of Batch Normalization with multi-layer neural network
Load the network modeled with Rhinoceros in Python ②
I ran the neural network on the actual FPGA
I will explain about the neural network "Differentiable Neural Computing (DNC)" with external memory.
Load the network modeled with Rhinoceros in Python ①
Parametric Neural Network
I ran the TensorFlow tutorial with comments (first neural network: the beginning of the classification problem)
Train MNIST data with a neural network in PyTorch
The story of making a music generation neural network
Implement Convolutional Neural Network
Implement Neural Network from 1
Convolutional neural network experience
What I was addicted to when I built my own neural network using the weights and biases I got with scikit-learn's MLP Classifier.
Create a web application that recognizes numbers with a neural network
Try to build a deep learning / neural network with scratch
Python sample to learn XOR with genetic algorithm with neural network
A network diagram was created with the data of COVID-19.
Image classification with self-made neural network by Keras and PyTorch
Try to automate the operation of network devices with Python
[Deep learning] Image classification with convolutional neural network [DW day 4]
Generalized linear model (GLM) and neural network are the same (2)