首页 > 解决方案 > 如何在 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());    

标签: deeplearning4j

解决方案


使用ModelSerializer

你可以像这样写/读它

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

...

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

推荐阅读