0

I have created a keras model in python imported into java

model = KerasModelImport.
                importKerasSequentialModelAndWeights(aiModelPath);

then i passed an array of values to the model and asked for a prediction or better said for classification

        INDArray x_2d = Nd4j.createFromArray(sensorValue);
        INDArray prediction = model.output(x_2d);

my output ist nice and korrect

System.out.println(prediction);
     [[    0.9773,    0.0227]]

what i need is the loss function and the accuracy from this predicted values:

model.output(x_2d);

How can i get the values, any idea?

ofitz
  • 1

1 Answers1

0

you can use evaluation: https://deeplearning4j.konduit.ai/tuning-and-training/evaluation

Summarizing this page for what to look for: Basic idea is you can use a datasetiterator (iterates through the data in minibatches). DataSetIterator myTestData = ... Evaluation eval = model.evaluate(myTestData);

or you can use the in memory approach: Evaluation eval = new Evaluation(3); INDArray output = model.output(testData.getFeatures()); eval.eval(testData.getLabels(), output); log.info(eval.stats());

The eval.stats() will automatically calculate a lot of metrics.

Adam Gibson
  • 3,055
  • 1
  • 10
  • 12
  • i dont know how can i create **DataSetIterator** my value(INDArray) input(450values) shows. **[[-6277.0000,-6326.0000, ... -6326.0000,-6297.0000,-6290.0000]]** and my imported model have 2 Classes for clasification this Array – ofitz Jul 23 '20 at 08:19
  • You can also just create a dataset by passing in the labels and the features with new DataSet(INDArray,INDArray) where those are the inputs and the labels. Your labels being an ndarray are going to be relative to what you're doing (classification or regression) For classification, you can use FeatureUtil: https://deeplearning4j.org/api/latest/org/nd4j/linalg/util/FeatureUtil.html – Adam Gibson Jul 25 '20 at 12:28