Tflite custom object detection model for flutter application using google mlkit object detection package

0 votes

I'm trying to create a custom object detection model in tflite format so that I can use it in a flutter application with the google_mlkit_object_detection package.

The first few models, I created using yolov8 and converted to tflite. The annotations were made with roboflow and the google colab notebook I used was provided by them, the metadata of the converted tflite model looks like the following image

enter image description here

On this model I was getting the error

Input tensor has type kTfLiteFloat32: it requires specifying NormalizationOptions metadata to preprocess input images.

So as suggested I tried to change the metadata and add normalizationOptions but failed to do so. My second alternative was to train a model with the official TensorFlow google colab notebook TensorFlow Lite Model Maker and it generated a model with the following metadata

enter image description here

For this model the error was

Unexpected number of dimensions for output index 1: got 3D, expected either 2D (BxN with B=1) or 4D

So I checked the model from the example app from the package I am using "google_mlkit_object_detection" and the metadata looks like this

enter image description here

So my question is, how can I alter the models I already trained whichever it is easier, to look like this, both input and output, do I have to alter my model's architecture or just the metadata? The second one trained with the official notebook from tensor flow, it seems that all I have to do is include the correct shape format [1,N], but again I might have to change the architecture.

Apr 17, 2023 in Flutter by sarit
• 1,830 points
1,520 views

1 answer to this question.

0 votes

It seems like the issue is with the input and output shapes of your custom object detection model, which do not match the expected shapes of the google_mlkit_object_detection package.

You can try modifying your model's architecture to match the expected input and output shapes. Alternatively, you can modify the metadata of your existing models to match the expected shapes, but this may require some trial and error.

To modify the metadata, you can use the TensorFlow Lite Metadata Writer API or a metadata editor tool such as Netron. You would need to update the metadata to include the correct input and output shapes, as well as any other required information such as normalization options.

Once you have updated the metadata, you can use the google_mlkit_object_detection package to load the model and perform object detection in your Flutter app.

To know more about Flutter, join our Flutter APP Development Course today.

answered Apr 17, 2023 by Tej

Related Questions In Flutter

0 votes
1 answer
0 votes
1 answer

How to scan for bluetooth printers and print pdf or image via bluetooth in flutter?

The user wants to scan for Bluetooth ...READ MORE

answered Apr 4, 2023 in Flutter by seena
1,541 views
0 votes
1 answer

How to disable bouncing animation for pageview in flutter

To disable bouncing animation for PageView in ...READ MORE

answered Apr 10, 2023 in Flutter by Anitha
5,137 views
0 votes
1 answer

zegocloud's video/audio sdk flutter package error

It seems like there are some issues ...READ MORE

answered Apr 11, 2023 in Flutter by pooja
646 views
0 votes
1 answer

What is the future of flutter?

Hi@MD, Flutter is a rather new cross-platform framework ...READ MORE

answered Jul 17, 2020 in Others by akhtar
• 38,230 points
951 views
0 votes
1 answer

What is Flutter?

Hi@akhtar, Flutter is an app SDK for building ...READ MORE

answered Jul 17, 2020 in Others by MD
• 95,440 points
1,113 views
0 votes
1 answer

How to install Flutter in Windows system?

Hi@akhtar, You can follow the below-given steps to ...READ MORE

answered Jul 17, 2020 in Others by MD
• 95,440 points
1,555 views
0 votes
1 answer

How to save to local storage using Flutter?

Yes, Flutter has a built-in mechanism for ...READ MORE

answered Mar 28, 2023 in Flutter by Tej
1,797 views
0 votes
1 answer

Flutter TextField set textAlign for each line separately

By default, TextField widget aligns the text ...READ MORE

answered Apr 11, 2023 in Flutter by Tej
1,637 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP