Home

Awesome

<p align="center"> <br> <img src="https://github.com/am15h/tflite_flutter_plugin/raw/update_readme/docs/tflite_flutter_cover.png"/> </br> </p> <p align="center"> <a href="https://flutter.dev"> <img src="https://img.shields.io/badge/Platform-Flutter-02569B?logo=flutter" alt="Platform" /> </a> <a href="https://pub.dartlang.org/packages/tflite_flutter"> <img src="https://img.shields.io/pub/v/tflite_flutter.svg" alt="Pub Package" /> </a> <a href="https://pub.dev/documentation/tflite_flutter/latest/tflite_flutter/tflite_flutter-library.html"> <img alt="Docs" src="https://readthedocs.org/projects/hubdb/badge/?version=latest"> </a> <a href="https://opensource.org/licenses/Apache-2.0"><img src="https://img.shields.io/badge/License-Apache%202.0-blue.svg"></a> </a> </p>

Announcement

Update: 26 April, 2023

The TensorFlow team has officially migrated this project to a new repository, deprecating this one. We will be focusing on getting the plugin to a stable and usable state to help our developers add robust machine learning features to their Flutter apps. PRs and contributions are more than welcome there, though please be mindful that this is a work in progress, so some things may be a bit broken for a bit :)

We do want to say a huge thank you to Amish for working on this initial plugin, and we're excited to keep it progressing.

Feel free to reach out to me with questions until then.

Thanks!

Overview

TensorFlow Lite Flutter plugin provides a flexible and fast solution for accessing TensorFlow Lite interpreter and performing inference. The API is similar to the TFLite Java and Swift APIs. It directly binds to TFLite C API making it efficient (low-latency). Offers acceleration support using NNAPI, GPU delegates on Android, Metal and CoreML delegates on iOS, and XNNPack delegate on Desktop platforms.

Key Features

(Important) Initial setup : Add dynamic libraries to your app

Android

  1. Place the script install.sh (Linux/Mac) or install.bat (Windows) at the root of your project.

  2. Execute sh install.sh (Linux) / install.bat (Windows) at the root of your project to automatically download and place binaries at appropriate folders.

    Note: The binaries installed will not include support for GpuDelegateV2 and NnApiDelegate however InterpreterOptions().useNnApiForAndroid can still be used.

  3. Use sh install.sh -d (Linux) or install.bat -d (Windows) instead if you wish to use these GpuDelegateV2 and NnApiDelegate.

These scripts install pre-built binaries based on latest stable tensorflow release. For info about using other tensorflow versions follow instructions in wiki.

iOS

  1. Download TensorFlowLiteC.framework. For building a custom version of tensorflow, follow instructions in wiki.
  2. Place the TensorFlowLiteC.framework in the pub-cache folder of this package.

Pub-Cache folder location: (ref)

Desktop

Follow instructions in this guide to build and use desktop binaries.

TFLite Flutter Helper Library

A dedicated library with simple architecture for processing and manipulating input and output of TFLite Models. API design and documentation is identical to the TensorFlow Lite Android Support Library. Strongly recommended to be used with tflite_flutter_plugin. Learn more.

Examples

TitleCodeDemoBlog
Text Classification AppCode<img src="https://github.com/am15h/tflite_flutter_plugin/raw/master/example/demo.gif" width=120/>Blog/Tutorial
Image Classification AppCode<img src="https://github.com/am15h/tflite_flutter_helper/raw/master/example/image_classification/demo.gif" width=120/>-
Object Detection AppCode<img src="https://github.com/am15h/object_detection_flutter/raw/master/object_detection_demo.gif" width=120/>Blog/Tutorial
Reinforcement Learning AppCode<img src="https://github.com/windmaple/planestrike-flutter/raw/main/demo.gif" width=120/>Blog/Tutorial

Import

import 'package:tflite_flutter/tflite_flutter.dart';

Usage instructions

Creating the Interpreter

Refer to the documentation for info on creating interpreter from buffer or file.

Performing inference

See TFLite Flutter Helper Library for easy processing of input and output.

Closing the interpreter

interpreter.close();

Improve performance using delegate support

Note: This feature is under testing and could be unstable with some builds and on some devices.

Refer Tests to see more example code for each method.

Credits