Skip to content

edodm85/TF_Multi_Classifier

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 

Repository files navigation

TF Multi Classifier


What is TF Multi Classifier?

TF Multi Classifier App uses Tensorflow lite to classify camera frames in real time.

You can download from Google Play here:


Benchmark

Mean inference time:

Model Phone Android CPU 1TH CPU 2TH NNAPI GPU
mobilenet_v1_224 (FLOAT) Pixel 2XL 9 165ms 115ms 110ms 40ms
mobilenet_v1_224 (QUANTIZED) Pixel 2XL 9 85ms 50ms 80ms N/A
mobilenet_v1_224 (FLOAT) Nexus 5 6.0 180ms 200ms N/A N/A
mobilenet_v1_224 (QUANTIZED) Nexus 5 6.0 120ms 100ms N/A N/A
mobilenet_v1_224 (FLOAT) LG G6 8.0 260ms 220ms N/A 50ms
mobilenet_v1_224 (QUANTIZED) LG G6 8.0 220ms 140ms N/A N/A

Features

  • Classify with Tensorflow lite
  • Custom dataset
  • GPU supported (requires OpenGL ES 3.1 or higher)

Download Dataset

You can download the following datasets from HERE:

  • Dog Breed (created with Transfer learning)
  • Dog Vs Cat (created with Transfer learning)
  • Google Datasets: (converted from google pb dataset)
    • Bird
    • Insect
    • Plant
    • Seefood


Transfer learning

An easy and fast way for train a model is to use "Transfer learning".

"Transfer learning" provides the opportunity to adapt a pre-trained model (a model that has been already trained) to new classes of data. This concept is summarized in three steps:

  • download the pre-trained model
  • adds a new final layer
  • train that new layer

Step 1: Install tensorflow (following the official tutorial HERE)


Step 2: Clone this Git repository:

git clone https://github.com/googlecodelabs/tensorflow-for-poets-2

and "cd" into the following directory:

cd tensorflow-for-poets-2

Step 3: Before you start any training, you'll need a set of images to teach the model about the new classes you want to recognize. Download the photos:

Flower photos by google:

curl http://download.tensorflow.org/example_images/flower_photos.tgz \
    | tar xz -C tf_files

or download your images from google images in a structure like this:

tf_files/name_class/
      class1/[images...]
      class2/[images...]
      class3/[images...]

PS: set this folder in "--image_dir"


Step 4: Run the training with this command:

python -m scripts.retrain \
  --bottleneck_dir=tf_files/bottlenecks \
  --model_dir=tf_files/models/ \
  --summaries_dir=tf_files/training_summaries/mobilenet_1.0_224 \
  --output_graph=tf_files/retrained_graph_mobilenet_1.0_224.pb \
  --output_labels=tf_files/retrained_labels.txt \
  --architecture=mobilenet_1.0_224 \
  --image_dir=tf_files/flower_photos

This script downloads the pre-trained model and trains that layer on the flower photos you've downloaded. In this script I used "mobilenet_1.0_224" a MobileNet (small efficient convolutional neural network) with image resolution 224px and size of model 1.0.

You can use other configurations, for example:

  • mobilenet_A_B with A: 128, 160, 192, or 224px and B: 1.0, 0.75, 0.50, or 0.25.
  • inception_v3

Step 5: Now we have these two file:

  • retrained_labels.txt: text file containing labels.
  • retrained_graph_mobilenet_1.0_224.pb: contains a version of the selected network with a final layer retrained on your categories.

Step 6: Convert the model ".pb" in ".tflite" for tensorflow lite.

I tryed to use tflite_convert in windows without positive results. So I installed ubuntu in a virtual machine, installed tensorflow and now the conversion works.

tflite_convert \
  --output_file=tf_files/retrained_graph_lite.tflite \
  --graph_def_file=tf_files/retrained_graph.pb \
  --input_arrays=Mul \
  --output_arrays=final_result

Step 7: Now you can load this two file in my Android App:

  • retrained_graph_lite.tflite
  • retrained_labels.txt


License

Copyright (C) 2018 edodm85.
Licensed under the MIT license.
(See the LICENSE file for the whole license text.)