iwatake2222 / play_with_tflite

Sample projects for TensorFlow Lite in C++ with delegates such as GPU, EdgeTPU, XNNPACK, NNAPI
Apache License 2.0
353 stars 79 forks source link

Mobilenet SSD V1 Get Different Results on Same Image #28

Closed yyuzhongpv closed 2 years ago

yyuzhongpv commented 2 years ago

Issue report

issue

Environment (Hardware)

Android 9, call the inference model in JNI and using same version of TF lite as mentioned in this repo.

Project Name

pj_tflite_det_mobilenetssd_v1

Issue Details

I tried to run the detection pj_tflite_det_mobilenetssd_v1 on Android. For the same image, I got different detection in multiple inferences.

For example, the first time I got this result:

image

And for the second time, it may get same or a little different result such as:

image

I logged the input data and confirmed the input data is same. I also tried different options, CPU, GPU, NNAPI etc. and get similar results. On Desktop PC, it looks good, and I only found this issue on Android phone.

How to Reproduce

Steps to reproduce the behavior. Please include your cmake command.

Error Log

error log

Additional Information

Add any other context about the problem here.

iwatake2222 commented 2 years ago

One possible reason is you reuse the same input image object (Mat) for the 1st and the 2nd inference. The result (such as inference time, bounding boxes, etc.) is drawn onto the input image. So, the input images for the 1st and 2nd inference can be difference. It can be happen even if you store the Mat object like this.

Mat mat_original;
mat_original = get original input data;
Mat mat_1st = mat_original;
Mat mat_2nd = mat_original;
ImageProcessorProcess(mat_1st.getNativeObjAddr());    <- pixel data (of mat_original, mat_1st, mat_2nd) is over written
ImageProcessorProcess(mat_2nd.getNativeObjAddr());

I logged the input data and confirmed the input data is same.

Did you confirm all the input pixel data (not just the address of data) is the same when calling ImageProcessorProcess ? I can check if you share your code.

yyuzhongpv commented 2 years ago

Thanks for your kind reply. The root cause is exact as you said. Results were drawn on the frame due to the sync of detection thread and render thread.

I compare some lines of the input frames, not for each pixel. It's my bad.