google_ml_kit_flutter icon indicating copy to clipboard operation
google_ml_kit_flutter copied to clipboard

Custom object detection model giving wrong predictions on Android

Open DeepakSinghRawat opened this issue 3 years ago • 5 comments

Hi,

I am trying to use a custom object detection model in the example app provided by you. I am using the latest version of google_mlkit_object_detection: ^0.4.0 plugin.

I replaced the object_labeler.tflite model in the example app with a custom model. I want to get predictions using camera live feed. The model is predicting correct labels on iOS. But for some reason it's not predicting correct labels on Android. I am testing on Android 10. On Android it's predicting random values. If I use a single image from the gallery or take a picture then I am getting good predictions on Android also.

I used the same model in the ML Kit Vision Quickstart Sample Android App and it's giving correct predictions.

My current settings:

    final options = LocalObjectDetectorOptions(
      mode: mode,
      modelPath: modelPath,
      classifyObjects: true,
      multipleObjects: true,
    );

CameraController(
      camera,
      ResolutionPreset.high,
      enableAudio: false,
    );

I have tried to change ResolutionPreset to different values but nothing is working. Please guide me on how to resolve this issue.

DeepakSinghRawat avatar Jun 01 '22 19:06 DeepakSinghRawat

@DeepakSinghRawat: could you share your custom model, I will take a look.

fbernaly avatar Jun 01 '22 19:06 fbernaly

@fbernaly Please download the model from here.

I trained a fruit detection model using a pre-trained tf.keras.applications.MobileNetV3Large model. This model has in-built image normalization layer so I disabled normalization in TFLite model's metadata by setting mean=0 and std=1. This model is able to detect fruits like banana, tomato, apple, coconut in MLKit's android app but it's giving random predictions using your example app. I hope you will be able to point me in the right direction. Please let me know if you need any other information.

DeepakSinghRawat avatar Jun 02 '22 03:06 DeepakSinghRawat

@DeepakSinghRawat : I created this branch with you model: https://github.com/bharat-biradar/Google-Ml-Kit-plugin/tree/fruits_model

Give it a try.

I am not an expert in Machine Learning or trying models. I cannot tell you if the model is well trained or not, but so far the testing I did with my Pixel4 I am getting this:

Screenshot_20220602-151324

Screenshot_20220602-151309

fbernaly avatar Jun 02 '22 22:06 fbernaly

Dear @fbernaly Thank you for taking a look at the issue I am facing. I tried your repo on a few real fruits but got wrong predictions. For example here are the predictions from your flutter app and mlkit's android app. Flutter app is predicting apple which is wrong. mlkit's android app is predicting tomato for the same image which is correct. I even changed multipleObjects: false in the flutter app but still got wrong predictions most of the time. For the same images, the flutter app on iPhone is working fine. I am facing this issue only on Android.

I have created a new repo with mlkit's android app and my model in case you want to install it and compare the results. Here's the link Launch the app and choose: Run the ML Kit quickstart written in Java -> LivePreviewActivity -> Custom Object Detection

Original Image

original_tomatoes

Flutter App Prediction

flutter_app

MLKIT Android App Prediction

android_app

DeepakSinghRawat avatar Jun 03 '22 15:06 DeepakSinghRawat

I'm having a similar problem when trying to use our custom model in the object detection example project. Seeing the same results as when the default assets/object_labeler.tflite model is used. Even when changing to a non-existing file path the app gives no errors but showing same results regardless.

Heech avatar Sep 14 '22 00:09 Heech