title: tensorflow TF lite android app crashing after detection
body: <p>I have trained my model using <a href="https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/detection_model_zoo.md" rel="nofollow noreferrer">ssd_mobilenet_v2_quantized_coco</a>, which was also a long painstaking process of digging. Once training was successful, the model was correctly detecting images from my laptop but on my phone  as soon as an object is detected, app crashes. I used TF lite Android app available at <a href="https://github.com/tensorflow/tensorflow/tree/master/tensorflow/lite/examples/android/app" rel="nofollow noreferrer">GitHub</a>. I did some debugging on Android Studio and getting the following error log when an object gets detected and app crashes:</p>
  
  <pre><code>I/tensorflow: MultiBoxTracker: Processing 0 results from 314 I/tensorflow: 
  
  DetectorActivity: Preparing image 506 for detection in bg thread.
  
  I/tensorflow: DetectorActivity: Running detection on image 506
  
  I/tensorflow: MultiBoxTracker: Processing 0 results from 506
  
  I/tensorflow: DetectorActivity: Preparing image 676 for detection in bg thread.
  
  I/tensorflow: DetectorActivity: Running detection on image 676
  
  E/AndroidRuntime: FATAL EXCEPTION: inference
      Process: org.tensorflow.lite.demo, PID: 3122
      java.lang.ArrayIndexOutOfBoundsException: length=80; index=-2147483648
          at java.util.Vector.elementData(Vector.java:734)
  
      at java.util.Vector.get(Vector.java:750)
      at org.tensorflow.demo.TFLiteObjectDetectionAPIModel.recognizeImage(TFLiteObjectDetectionAPIModel.java:213)
      at org.tensorflow.demo.DetectorActivity$3.run(DetectorActivity.java:247)
      at android.os.Handler.handleCallback(Handler.java:873)
      at android.os.Handler.dispatchMessage(Handler.java:99)
      at android.os.Looper.loop(Looper.java:193)
      at android.os.HandlerThread.run(HandlerThread.java:65)
  </code></pre>
  
  <p>My guess is labels located in .txt file being somehow misread. This is because of the line:</p>
  
  <blockquote>
    <p>at org.tensorflow.demo.TFLiteObjectDetectionAPIModel.recognizeImage(TFLiteObjectDetectionAPIModel.java:213)</p>
  </blockquote>
  
  <p>and that line corresponds to the following code:</p>
  
  <pre><code>labels.get((int) outputClasses[0][i] + labelOffset)
  </code></pre>
  
  <p>However, I don't know what to change in labels.txt. Possibly, I need to edit that txt as suggested <a href="https://stackoverflow.com/questions/47976743/tensorflow-object-detection-api-index-out-of-bounds">here</a>. Any other suggestions and explanation for possible causes are appreciated.</p>
  
  <p>Update. I added ??? to the labels.txt and compiled/run, but I am still getting the same error as above.
  P.S. I trained ssdmobilenet_V2_coco (the model without quantization) as well and it is working without crash on the app. I am guessing, perhaps, quantization is converting label indices differently and maybe resulting in outofbound error for labels. </p>