tensorflow / models

Models and examples built with TensorFlow
Other
77.04k stars 45.77k forks source link

can't run mobilenetv2 ssdlite FLOAT in Android Studio #7593

Open kiad4631 opened 5 years ago

kiad4631 commented 5 years ago

Hi guys. I did every steps in https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/running_on_mobile_tensorflowlite.md but I can't n my FLOAT mobilenetv2 ssdlite on android. and when I run get this error:

java.lang.ArrayIndexOutOfBoundsException: length=160; index=-11

can anyone help me?

tensorflowbutler commented 5 years ago

Thank you for your post. We noticed you have not filled out the following field in the issue template. Could you update them if they are relevant in your case, or leave them as N/A? Thanks. What is the top-level directory of the model you are using Have I written custom code OS Platform and Distribution TensorFlow installed from TensorFlow version Bazel version CUDA/cuDNN version GPU model and memory Exact command to reproduce

kiad4631 commented 5 years ago

Have I written custom code :NO OS Platform and Distribution:Ubuntu 18.04 TensorFlow installed from:Source TensorFlow version:15 Bazel version:0.27 CUDA/cuDNN version: GPU model and memory:

Tanmay-Kulkarni101 commented 4 years ago

There are two things you should have accounted for

  // Configuration values for the prepackaged SSD model.
  private static final int TF_OD_API_INPUT_SIZE = 300;
  private static final boolean TF_OD_API_IS_QUANTIZED = false;
  private static final String TF_OD_API_MODEL_FILE = "detect.tflite";
  private static final String TF_OD_API_LABELS_FILE = "file:///android_asset/labelmap.txt";
  private static final DetectorMode MODE = DetectorMode.TF_OD_API;

The details, with respect to the inputs. The input has to be 300x300.

Second, is to change the code below

      recognitions.add(
          new Recognition(
              "" + i,
              labels.get((int) outputClasses[0][i] + labelOffset),
              outputScores[0][i],
             detection));

With the following code-

        final int classLabel = (int) outputClasses[0][i] + labelOffset;
        if (inRange(classLabel, labels.size(), 0) && inRange(outputScores[0][i], 1, 0)) {
            recognitions.add(
                    new Recognition(
                            "" + i,
                            labels.get(classLabel),
                            outputScores[0][i],
                            detection));
        }
    }
    Trace.endSection(); // "recognizeImage"
    return recognitions;
  }

private boolean inRange(float number, float max, float min) {
    return number < max && number >= min;
}

I hope this helps.

voqtuyen commented 4 years ago

@Tanmay-Kulkarni101 @tensorflowbutler i had the same problem, and when i check i see that values of outputClasses are random and also negative. Do you have any solution?

It seems that your code is just a temporary solution. outputClasses should not be negative

Tanmay-Kulkarni101 commented 4 years ago

@voqtuyen You need to make sure that the model that you use should match with the outputs you are trying to obtain. Thus, if you want float outputs, you make use of a model that gives float outputs and the same applies for integer values.

The code that I had mentioned in the above comment talks about converting the sample code for tensorflow examples to take discrete values, without making use of a quantized model.