Giter Club home page Giter Club logo

flttf's Introduction

flttf

A demonstration to use TensorFlow Lite in a Flutter project.

Handwritten digits recognition

Train the model

A simple neural network is trained for the handwritting recognizer, using the MNIST dataset, see mnist.py or mnist.ipynb for details.

Fits the model and save it to a tflite file:

# prepare the virtualenv
pipenv --python `which python3` install

# fits the model
pipenv run python mnist.py

You can also do further experiments using the Jupyter Notebook:

pipenv run jupyter notebook mnist.ipynb

Real-time object detection

Use the pre-trained Tiny YOLO v2 model.

Convert the saved model file

Prepare a virtualenv with TensorFlow 1.x installed, using Pipenv for example:

pipenv --python `which python3` install tensorflow==1.15 opencv-python keras cython

install darkflow:

pipenv shell
git clone https://github.com/thtrieu/darkflow.git
cd darkflow
pip3 install -e .

download the Tiny YOLO v2 model files:

curl https://pjreddie.com/media/files/yolov2-tiny.weights -o yolov2-tiny.weights
curl https://raw.githubusercontent.com/pjreddie/darknet/master/cfg/yolov2-tiny.cfg -o yolov2-tiny.cfg
curl https://raw.githubusercontent.com/pjreddie/darknet/master/data/coco.names -o labels.txt

convert weights to pb, and then tflite:

# convert to pb
flow --model yolov2-tiny.cfg --load yolov2-tiny.weights --savepb

# convert to tflite
tflite_convert \
  --graph_def_file=built_graph/yolov2-tiny.pb \
  --output_file=yolov2-tiny.tflite \
  --input_format=TENSORFLOW_GRAPHDEF \
  --output_format=TFLITE \
  --input_shape=1,416,416,3 \
  --input_array=input \
  --output_array=output \
  --inference_type=FLOAT \
  --input_data_type=FLOAT

the output will be a yolov2-tiny.tflite file under the current directory.

Test the converted model

Enter the directory which built_graph located when you generate the .pb file using darkflow, put any test images into sample_img directory, and run the following command:

flow --metaLoad built_graph/yolov2-tiny.meta --pbLoad built_graph/yolov2-tiny.pb

labled images should be generated in sample_img/out directory, so that you can preview the result of object detection.

flttf's People

Contributors

xinthink avatar

Watchers

 avatar  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.