A Flutter plugin to access TensorFlow Lite apis.

Overview

tensorflow_lite

pub package

A Flutter plugin to access TensorFlow Lite apis. TensorFlow Lite is TensorFlow’s lightweight solution for mobile and embedded devices. With TensorFlow Lite you can deploy machine learning models on phones in your Android/iOS app.

Usage

Add tensorflow_lite to your pubspec.yaml

Copy your models to an asset dir like assets/mobilenet_quant_v1_224.tflite And add it to your pubspec.yaml

   assets:
     - assets/mobilenet_quant_v1_224.tflite

Import tensorflow_lite in your app

import 'package:tensorflow_lite/tensorflow_lite.dart';

Create a new Interpreter instance based on your tflite model file

Interpreter model = await Interpreter.createInstance(modelFilePath: modelPath);

Pass some bytes to the model to get the output

dynamic result = await _interpreter.run(imageToByteList(image), new Uint8List(_labelList.length));

Image Classification example

tensorflow_lite also includes a wrapper for image classification models which can be easily loaded without much of boilerplate code.

Future<Null> loadRecognitions() async {
    var classifier = await TFLiteImageClassifier.createInstance(
      assets: rootBundle,
      modelPath: "assets/mobilenet_quant_v1_224.tflite",
      labelPath: "assets/labels.txt",
      inputSize: 224,
    );
    print('Classifier ready');
    var imageBytes = (await rootBundle.load("assets/cat500.png")).buffer;
    img.Image image = img.decodePng(imageBytes.asUint8List());
    image = img.copyResize(image, 224, 224);
    _recognitions = await classifier.recognizeImage(image);
    setState(() {});

    await classifier.close();
  }

Please check the example for full usage.

Note

  • Works only on Android
  • Tested only on image classification

Contributing

I am new to Flutter and I haven't worked on iOS yet. So if you are an iOS developer, i'd be glad to receive some contribution. Just send a PR or open up an issue!

You might also like...

A Flutter plugin for iOS and Android allowing access to the device cameras.

Camera Plugin A Flutter plugin for iOS and Android allowing access to the device cameras. Note: This plugin is still under development, and some APIs

Mar 17, 2020

A Flutter plugin for Android and iOS allowing access to the device cameras, a bit deeper!!

flutter_cameraview A Flutter plugin for Android and iOS allowing access to the device cameras, a bit deeper!!. This plugin was created to offer more a

Oct 22, 2022

A Flutter sensor plugin which provide easy access to the Pitch and Roll on Android and iOS devices.

A Flutter sensor plugin which provide easy access to the Pitch and Roll on Android and iOS devices.

Flutter Aeyrium Sensor Plugin Aeyrium Sensor Plugin A Flutter sensor plugin which provide easy access to the Pitch and Roll on Android and iOS devices

Nov 3, 2022

System info plus - A Flutter plugin to get device Random Access Memory (RAM) size

system_info_plus A Flutter plugin to get device Random Access Memory (RAM) size.

Aug 21, 2022

A Flutter plugin for iOS and Android allowing access to the device cameras.

A Flutter plugin for iOS and Android allowing access to the device cameras.

Jan 8, 2023

dna, dart native access. A lightweight dart to native super channel plugin

dna, dart native access. A lightweight dart to native super channel plugin, You can use it to invoke any native code directly in contextual and chained dart code.

Jul 11, 2022

A Flutter plugin that provides assets abstraction management APIs without UI integration, you can get assets (image/video/audio) on Android, iOS and macOS.

A Flutter plugin that provides assets abstraction management APIs without UI integration, you can get assets (image/video/audio) on Android, iOS and macOS.

photo_manager Photo/Assets management APIs for Flutter without UI integration, you can get assets (image/video/audio) from Android, iOS and macOS. 提供相

Jan 4, 2023

Flutterbodydetection - A flutter plugin that uses MLKit on iOS/Android platforms to enable body pose and mask detection using Pose Detection and Selfie Segmentation APIs for both static images and live camera stream.

Flutterbodydetection - A flutter plugin that uses MLKit on iOS/Android platforms to enable body pose and mask detection using Pose Detection and Selfie Segmentation APIs for both static images and live camera stream.

body_detection A flutter plugin that uses MLKit on iOS/Android platforms to enable body pose and mask detection using Pose Detection and Selfie Segmen

Dec 5, 2022

Ml kit ocr - Plugin which provides native ML Kit OCR APIs

MLKit OCR Plugin which provides native ML Kit OCR APIs Requirements Android Set

Aug 3, 2022
Comments
  • Await function does not gets execute.

    Await function does not gets execute.

    I have taken the sample example as shown README.md (which is same as mentioned at https://pub.dartlang.org/packages/tensorflow_lite#-example-tab- ) with appropriate instruction.

    When I run the app keeps on loading; when debugged, the below await function gets stuck and does not responds with no output/error message. var classifier = await TFLiteImageClassifier.createInstance( assets: rootBundle, modelPath: "assets/assetsmobilenet_quant_v1_224.tflite", labelPath: "assets/labels.txt", inputSize: 224, );

    My pubspec.yaml- `name: ai_edge description: A new Flutter project.

    dependencies: flutter: sdk: flutter

    cupertino_icons: ^0.1.0 tensorflow_lite: ^0.0.3 image: ^1.1.32

    dev_dependencies: flutter_test: sdk: flutter

    assets: - assets/mobilenet_quant_v1_224.tflite - assets/cat_Image.jpg- - assets/labels.txt

    flutter: uses-material-design: true `

    Is there something which I missed.

    opened by sachinpatel248 6
  • your sample does it not work

    your sample does it not work

    Hello, I have tried to run your example, but unfortunately it does not work. You have tried it, it works for you ?. Thanks for your time and information.

    rhelena

    opened by rhelenagh 4
Face Mask Detection with Tensorflow(Flutter)Face Mask Detection with Tensorflow(Flutter)

Face Mask Detection with Tensorflow(Flutter) Face Mask Detection With TFlite Info An app made with flutter and tensor flow lite for face mask detectio

Mohsen Mirdar 1 May 23, 2022
Flutter realtime object detection with Tensorflow Lite

Flutter realtime object detection with Tensorflow Lite Flutter realtime object d

null 0 Dec 25, 2021
Simple face recognition authentication (Sign up + Sign in) written in Flutter using Tensorflow Lite and Firebase ML vision library.

FaceNetAuthentication Simple face recognition authentication (Sign up + Sign in) written in Flutter using Tensorflow Lite and Google ML Kit library. S

Marcos Carlomagno 279 Jan 9, 2023
Face Mask Detection mobile application built with Flutter and TensorFlow lite in order to detect face masks using images and live camera.

Face Mask Detector App Face Mask Detection mobile application built with Flutter and TensorFlow lite in order to detect face masks using images and li

Yousef Shaban 3 Aug 15, 2022
Flutter plugin that leverages Storage Access Framework (SAF) API to get access and perform the operations on files and folders.

Flutter plugin that leverages Storage Access Framework (SAF) API to get access and perform the operations on files and folders.

Vehement 8 Nov 26, 2022
A mobile client for the public apis repository, 1400+ free apis to use able to be navigated through your phone :)

Public APIs mobile app Your assistant app that will help you discover and pick the next API for your next development project What it contains, you sa

Gwhyyy 4 Dec 25, 2022
Learn how to build a tensorflow model on Techable Machine and then run it on flutter app.

Ml With Flutter Learn how to build a tensorflow model on Techable Machine and then run it on flutter app. Youtube Tutorial Show Support Recommend Me O

Sanskar Tiwari 133 Jan 3, 2023
Lite version of smart_select package, zero dependencies, an easy way to provide a single or multiple choice chips.

Lite version of smart_select package, zero dependencies, an easy way to provide a single or multiple choice chips. What's New in Version 2.x.x Added p

Irfan Vigma Taufik 97 Dec 15, 2022
Lite-graphql - A light way implementation of GraphQL client in dart language

lite GraphQL client A light way implementation of GraphQL client in dart languag

Vincenzo Palazzo 3 Mar 17, 2022
Interactive command line interface Couchbase Lite REPL utility built with the Dart

Couchbase Lite Dart CLI Interactive command line interface Couchbase Lite REPL utility built with the Dart programming language. This code uses the cb

Pieter Greyling 2 Jul 20, 2022