flutter-ml / google_ml_kit_flutter

A flutter plugin that implements Google's standalone ML Kit
MIT License
912 stars 709 forks source link

_imageLabeler.processImage(inputImage); produce almost the same results with all images. #524

Closed ChurikiTenna closed 10 months ago

ChurikiTenna commented 10 months ago

Describe the bug I trained my model with approx. 400 images, and run the model on flutter. But, the model produces almost the same result with all images (such as an image of blank wall, or an image of certain object...).

To Reproduce I trained 7 categories with approx. 60 images each. Last tflite training log result accuracy of 0.6.

8/8 [==============================] - 1s 77ms/step - loss: 0.9956 - accuracy: 0.6116 - val_loss: 1.5415 - val_accuracy: 0.3167

I assume the model is not trained enough?? Or am I missing something? I know it is not enough for the production, but I expected that it can guess better.

Code:

        var inputImage = _inputImageFromCameraImage(currentimage!)!;
        var labels = await _imageLabeler.processImage(inputImage);
        print("labels ${labels.map((e) => '${e.label}: ${e.confidence}')}");

_imageLabeler.processImage log:

flutter: labels (normal20: 3.0371227264404297, normal24: 1.2958755493164062)
flutter: labels (normal20: 3.025402545928955, normal24: 1.2920397520065308)
flutter: labels (normal20: 3.0361475944519043, normal24: 1.2833253145217896)
flutter: labels (normal20: 3.0555901527404785, normal24: 1.2898293733596802)
flutter: labels (normal20: 3.0952048301696777, normal24: 1.2871267795562744)
flutter: labels (normal20: 3.106173038482666, normal24: 1.2843830585479736)
flutter: labels (normal20: 3.178009510040283, normal24: 1.3074455261230469)
flutter: labels (normal20: 3.1779122352600098, normal24: 1.3082518577575684)
flutter: labels (normal20: 3.177504062652588, normal24: 1.3079755306243896)
flutter: labels (normal20: 3.026615619659424, normal24: 1.288081169128418)
flutter: labels (normal20: 3.059936761856079, normal24: 1.2838897705078125)
flutter: labels (normal20: 3.12568998336792, normal24: 1.2795668840408325)

Expected behavior It should be able to roughly distinguish what the labels are.

Platform (please complete the following information):

fbernaly commented 10 months ago

Make sure to follow this tutorial: https://github.com/flutter-ml/mlkit-custom-model

Pay special attention to the Metadata section.

Run the tutorial in Google Colab: https://colab.research.google.com/github/flutter-ml/mlkit-custom-model/blob/main/ml_kit_custom_model.ipynb

ChurikiTenna commented 10 months ago

Thank you for the tutorial! I could never found it for some reasons. I'll follow the tutorial and let you know how it goes.

ChurikiTenna commented 10 months ago

I followed the tutorial (basically copied all lines) and the predictions significantly improved!! Thank you so much @fbernaly !!

Log: labels (normal8: 8.861006736755371, normal4: 7.560824394226074, normal2: 5.855652332305908, normal12: 1.419419765472412, normal20: 0.5430938005447388)

ChurikiTenna commented 10 months ago

Ok, I thought the prediction improved, turns out, it was generating almost same results to all images after all. I guess my training data is bad.

flutter: labels (normal8: 8.851354598999023, normal4: 8.038700103759766, normal2: 6.131048202514648, normal12: 1.9037384986877441)
flutter: labels (normal8: 9.227707862854004, normal4: 7.298639297485352, normal2: 6.035979747772217, normal12: 1.4222862720489502)
flutter: labels (normal8: 9.335094451904297, normal4: 7.643350124359131, normal2: 6.177713394165039, normal12: 1.5826878547668457)
flutter: labels (normal8: 9.33517837524414, normal4: 7.654670715332031, normal2: 6.25003719329834, normal12: 1.6401894092559814)
flutter: labels (normal8: 8.866486549377441, normal4: 8.136223793029785, normal2: 6.065356254577637, normal12: 1.9531581401824951)