1 /* Copyright 2018 The TensorFlow Authors. All Rights Reserved. 2 3 Licensed under the Apache License, Version 2.0 (the "License"); 4 you may not use this file except in compliance with the License. 5 You may obtain a copy of the License at 6 7 https://www.apache.org/licenses/LICENSE-2.0 8 9 Unless required by applicable law or agreed to in writing, software 10 distributed under the License is distributed on an "AS IS" BASIS, 11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 See the License for the specific language governing permissions and 13 limitations under the License. 14 ==============================================================================*/ 15 package org.tensorflow.ovic; 16 17 import java.util.ArrayList; 18 19 /** Result class for inference run on a single image. */ 20 public class OvicClassificationResult { 21 22 /** Top K classes and probabilities. */ 23 public final ArrayList<String> topKClasses; 24 25 public final ArrayList<Float> topKProbs; 26 public final ArrayList<Integer> topKIndices; 27 28 /** Latency (ms). */ 29 public Long latencyMilli; 30 31 /** Latency (ns). */ 32 public Long latencyNano; 33 OvicClassificationResult()34 OvicClassificationResult() { 35 topKClasses = new ArrayList<>(); 36 topKProbs = new ArrayList<>(); 37 topKIndices = new ArrayList<>(); 38 latencyMilli = -1L; 39 latencyNano = -1L; 40 } 41 42 @Override toString()43 public String toString() { 44 String textToShow = latencyMilli + "ms"; 45 textToShow += "\n" + latencyNano + "ns"; 46 for (int k = 0; k < topKProbs.size(); ++k) { 47 textToShow += 48 "\nPrediction [" 49 + k 50 + "] = Class " 51 + topKIndices.get(k) 52 + " (" 53 + topKClasses.get(k) 54 + ") : " 55 + topKProbs.get(k); 56 } 57 return textToShow; 58 } 59 } 60