3

deeplearning4j : How can I store/save a trained model on persistence level and load it back when an ad-hoc request comes to evaluate the deep learning model?

        DataNormalization normalizer = new NormalizerStandardize();
        normalizer.fit(trainingData);           //Collect the statistics (mean/stdev) from the training data. This does not modify the input data
        normalizer.transform(trainingData); 

        //run the model
        MultiLayerNetwork model = new MultiLayerNetwork(conf);
        model.init();
        model.setListeners(new ScoreIterationListener(100));

        for( int i=0; i<epochs; i++ ) {
            model.fit(trainingData);
        }

I need to store the trained model. How can I do this? With which Api?

        //evaluate the model on the test set
        Evaluation eval = new Evaluation(3);
        INDArray output = model.output(testData.getFeatures());

        eval.eval(testData.getLabels(), output);
        log.info(eval.stats());    
David
  • 5,882
  • 3
  • 33
  • 44

1 Answers1

3

With the ModelSerializer

You can write/read it like this

ModelSerializer.writeModel(modelToSave, "location", true);

...

MultiLayerNetwork model = ModelSerializer.restoreMultiLayerNetwork("location");
fkajzer
  • 179
  • 11