A flutter plugin to run your custom retrain model from MobileNet. This plugin is under development API's might change.
- Android implementation
- iOS implementation
- Live preview
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.
cd example
flutter run
dependencies:
flutter_web_browser:
path: git: git@github.com:victorbonnet/flutter_tflite_detector.git
import 'package:flutter_tflite_detector/flutter_tflite_detector.dart';
- 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;
}