如何在deeplearning4j中存储和加载经过训练的数据?

时间:2018-12-19 23:26:42

标签: deeplearning4j

deeplearning4j:如何在持久性级别上存储/保存训练好的模型并将其加载回临时评估深度学习模型的请求中?

        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);
        }

我需要存储经过训练的模型。我怎样才能做到这一点?与哪个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());    

1 个答案:

答案 0 :(得分:0)

使用ModelSerializer

您可以这样编写/阅读它

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

...

MultiLayerNetwork model = ModelSerializer.restoreMultiLayerNetwork("location");