mdabros/SharpLearning.Examples

How to save and load a network ?

matteofabbri opened this issue · 1 comments

How to save and load a network ?

Loading and saving a neural net is done in same way as all the other models in SharpLearning. You can see an example with a RandomForestModel at the bottom of this wiki page: Introduction to SharpLearning

Here is a small example showing how to save a neural net model using the static methods:

var learner = new ClassificationNeuralNetLearner(net, iterations: 10, loss: new AccuracyLoss());
var model = learner.Learn(trainingObservations, trainingTargets);
   
// saving a neural net model
model.Save(() => new StreamWriter(@"c:\neuralnet.xml"));
   
// loading a neural net model
ClassificationNeuralNetModel.Load(() => new StreamReader(@"c:\neuralnet.xml"));

Alternatively, you can use one of the serializers as you can see on the wiki page above.