From afbb215e540154c21bf8dc5bbf8f30d85265e6c6 Mon Sep 17 00:00:00 2001 From: richardbrks Date: Fri, 6 Dec 2019 14:19:15 -0500 Subject: [PATCH] iterate through less detections if returned less than max amount --- .../detection/tflite/TFLiteObjectDetectionAPIModel.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lite/examples/object_detection/android/app/src/main/java/org/tensorflow/lite/examples/detection/tflite/TFLiteObjectDetectionAPIModel.java b/lite/examples/object_detection/android/app/src/main/java/org/tensorflow/lite/examples/detection/tflite/TFLiteObjectDetectionAPIModel.java index 6ca254eb9ae..40017dc0bdf 100644 --- a/lite/examples/object_detection/android/app/src/main/java/org/tensorflow/lite/examples/detection/tflite/TFLiteObjectDetectionAPIModel.java +++ b/lite/examples/object_detection/android/app/src/main/java/org/tensorflow/lite/examples/detection/tflite/TFLiteObjectDetectionAPIModel.java @@ -37,6 +37,8 @@ import org.tensorflow.lite.Interpreter; import org.tensorflow.lite.examples.detection.env.Logger; +import static java.lang.Math.min; + /** * Wrapper for frozen detection models trained using the Tensorflow Object Detection API: * github.com/tensorflow/models/tree/master/research/object_detection @@ -196,7 +198,7 @@ public List recognizeImage(final Bitmap bitmap) { // Show the best detections. // after scaling them back to the input size. final ArrayList recognitions = new ArrayList<>(NUM_DETECTIONS); - for (int i = 0; i < NUM_DETECTIONS; ++i) { + for (int i = 0; i < min(numDetections[0], NUM_DETECTIONS); ++i) { final RectF detection = new RectF( outputLocations[0][i][1] * inputSize,