Git Product home page Git Product logo

flutter_tensorflow_lite's Introduction

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!

flutter_tensorflow_lite's People

Contributors

kashifmin avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.