Set of tools to benchmark performance of TensorFlow image classification networks on Android devices.
Folder android/
contains Android app project.
Folder scripts/
contains Python scripts for converting existing TensorFlow models to TensorFlow Lite models embeddable into the Android application.
Extends official TensorFlow Android example and adds new models and functionality to benchmark performance.
Use script generate.py
Generates 6 networks pre-trained with ImageNet and saves them to h5 format
- NASNetMobile with input image size 224x224
- EfficientNetB0 with input image size 224x224
- MobileNetV2 with input image size 96x96
- MobileNetV2 with input image size 128x128
- MobileNetV2 with input image size 160x160
- MobileNetV2 with input image size 224x224
Use script convert.py
Converts TensorFlow model in h5 format to TensorFlow Lite format with optional dynamic range quantization
Usage: python convert.py -i <input file> [-o <output file>] [-q <quantization level>] [-s <samples count>]
-q 0
- no quantization (default)-q 1
- dynamic range quantiation-q 2
- full integer quantization- this quantization level requires model to be calibrated using example input images, use
-s
parameter to control how many sample images are used for the calibration
- this quantization level requires model to be calibrated using example input images, use
Use script interpret.py
Evaluates TFLite image classification model
Usage: python interpret.py -m <path to model> [-s <samples count>]
Use script setMetadata.py
Inserts metadata into tflite model
Usage: python setMetadata.py
, then enter information after prompted by terminal
Use script getMetadata.py
Prints metadata from TFLite model file
Usage: python getMetadata.py -i <input .tflite file>
NetworkName_InputSize_QuantizationLevel_HasMetadata
Example:
generator.py
generatesMobileNetV2_224.h5
-MobileNetV2
with input size of224x224
convert.py
quantizatizes and converts this model to TF Lite format and appends Q followed by quantization level to filenameMobileNetV2_224_Q1.tflite
- quantization level of 1 (see quantization levels above)setMetadata.py
adds metadata to the model and appends_M
to filenameMobileNetV2_224_Q1_M.tflite