Skip to content

victorbonnet/flutter_tflite_detector

Repository files navigation

Flutter Tflite Detector

A flutter plugin to run your custom retrain model from MobileNet. This plugin is under development API's might change.

TODO

  • Android implementation
  • iOS implementation
  • Live preview

Getting Started

For help getting started with Flutter, view our online documentation.

The sample project use the model from the Tensorflow repository for object detection and a pet breed detector built following this very good tutorial.

Build the example

cd example
flutter run

Result samples

Object detector

screenshot_20180724-151122

Pets breed detector

screenshot_20180724-151134

Installation

dependencies:
  flutter_web_browser: 
    path: git: git@github.com:victorbonnet/flutter_tflite_detector.git

Import the library

import 'package:flutter_tflite_detector/flutter_tflite_detector.dart';

Execute you model with an image

  • Add the tflite file in your asset and the in pubspec.yaml
  • Add the labels file in your asset and the in pubspec.yaml
  • Create a detector with you custom model
    • Path of the custom model
    • Path of the label file
    • Image size expected by the model
    • Specify if the model is quantized
try {
  await FlutterTfliteDetector.createDetector(
      'assets/detector.tflite', 'assets/labels.txt', 300, true);
} on PlatformException catch (e) {
  debugPrint('Unable to create detector, ${e.message}');
}
  • Load an image and pass it to your detector
Future<bool> recognizeImageFromFile(String path) async {
  try {
    var imageBytes =
        (await rootBundle.load(path)).buffer;
  
    img.Image image = img.decodeJpg(imageBytes.asUint8List());
    image = img.copyResize(image, detector.imageSize, detector.imageSize); //stretch
  
      // Resize the image to the expected size for your model
      image = img.copyResize(image, detector.imageSize, detector.imageSize); //stretch
    
      var recognitions = await FlutterTfliteDetector.recognizeImage(image);
    return true;
  } on PlatformException {
    debugPrint('Unable to recognize image');
  }
  return false;
}

About

Flutter plugin to run retrained MobileNet model.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published