Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do i store and load trained data in deeplearning4j?

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());    
like image 325
Nabraj Khatri Avatar asked Dec 14 '25 05:12

Nabraj Khatri


1 Answers

With the ModelSerializer

You can write/read it like this

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

...

MultiLayerNetwork model = ModelSerializer.restoreMultiLayerNetwork("location");
like image 120
fkajzer Avatar answered Dec 16 '25 23:12

fkajzer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!