A Flutter plugin for accessing TensorFlow Lite. Supports both iOS and Android.
Add tflite
as a dependency in your pubspec.yaml file.
In android/app/build.gradle
file add the following setting in android
block.
aaptOptions {
noCompress 'tflite'
}
- Create a
assets
folder and place your label file and model file in it. Inpubspec.yaml
add:
assets:
- assets/labels.txt
- assets/mobilenet_v1_1.0_224.tflite
- Import the library:
import 'package:tflite/tflite.dart';
- Load the model and labels:
String res = await Tflite.loadModel(
model: "assets/mobilenet_v1_1.0_224.tflite",
labels: "assets/labels.txt",
);
- Run the model on a image file:
var recognitions = await Tflite.runModelOnImage(
path: filepath, // required
inputSize: 224, // wanted input size, defaults to 224
numChannels: 3, // wanted input channels, defaults to 3
imageMean: 127.5, // defaults to 117.0
imageStd: 127.5, // defaults to 1.0
numResults: 6, // defaults to 5
threshold: 0.05, // defaults to 0.1
numThreads: 1, // defaults to 1
);
- Release resources
await Tflite.close();
Refer to the example.