예제 #1
0
  public void predictOutput() {
    network.load(Settings.networkFile);

    for (int ntestSample = 0; ntestSample < networkInput.rows(); ntestSample++) {
      Mat testSample = networkInput.row(ntestSample);
      Mat classificationResult = new Mat(1, Settings.CLASSES, CvType.CV_32F);

      // System.out.println(testSample.dump());

      network.predict(testSample, classificationResult);

      // System.out.println(classificationResult.dump());

      int maxIndex = 0;
      double value = 0;
      double maxValue = classificationResult.get(0, 0)[0];

      for (int index = 1; index < Settings.CLASSES; index++) {
        value = classificationResult.get(0, index)[0];

        if (value > maxValue) {
          maxValue = value;
          maxIndex = index;
        }
      }

      if (networkOutput.get(ntestSample, maxIndex)[0] != 1) {

        for (int classIndex = 0; classIndex < Settings.CLASSES; classIndex++) {
          if (networkOutput.get(ntestSample, classIndex)[0] == 1) {
            results[classIndex][1]++;
          }
        }
      } else {
        results[maxIndex][0]++;
        results[maxIndex][1]++;
      }
    }
  }