0

I'm attempting to integrate a custom TensorFlow Lite (TFLite) model, created using Teachable Machine, into a Flutter app. Initially, I followed the live object detection example provided in the tflite_flutter plugin repository, specifically the live_object_detection_ssd_mobilenet example.

I successfully ran the example with the provided model (ssd_mobilenet.tflite), but when I replaced it with my custom TFLite model, the app ceased to function properly. Specifically, it no longer displayed bounding boxes and statistics for detected objects.

Here are the steps I took:

  1. Downloaded and replaced the default ssd_mobilenet.tflite model with my custom model.
  2. Updated the model path in detection_service.dart to point to my custom model.
  3. I check Netron and ensured that the mlModelInputSize in the code matches the input size used during training (224 instead of the default 300).
class _DetectorServer {
  /// Input size of image (height = width = 300)
  static const int mlModelInputSize = 300;

  /// Result confidence threshold
  static const double confidence = 0.5;
  Interpreter? _interpreter;
  List<String>? _labels;

  _DetectorServer(this._sendPort);

  final SendPort _sendPort;

  ...
}

Additional:

I'm new to tflite. I need a clear guidance to use my own model in the example that I provided above. If you have another suggestion or knowledge related to this issue, please let me know. Thank you.

1 Answer 1

0

First, your model is a classification model, not an object detection model. So, there are no bounding boxes. In Netron, you can see your output shape is [1,29], meaning there are 29 classes. If you print the output just after you infer the model, you will get the probabilities for each class like [[0.002,0.004,0.5,....]].

If you need to train your custom model for object detection, you will need to train it with an annotated dataset with bounding boxes. You can search for a Google Colab notebook to train your annotated data with SSD mobile net or something like yolo. The teachable machine is just for classification models.

Sign up to request clarification or add additional context in comments.

3 Comments

I tried to use my model and run another code example for image classification from this repo: github.com/tensorflow/flutter-tflite/tree/main/example/…, but the code is not working. is there a possible way to use teachable machine model to that example? Most tutorial I found is outdated and not using tflite_flutter package
You are using the correct example that suitable for your model. Without any error logs, or code samples, I would not be able to help you.
I post the issue on github, I appreciate it if you can take a look at it. github.com/tensorflow/flutter-tflite/issues/216

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.