TF2 [Object Detection API] Converting mobilenet-SSD models into .tflite uint8 format

Showing results for 
Search instead for 
Did you mean: 

TF2 [Object Detection API] Converting mobilenet-SSD models into .tflite uint8 format

NXP Employee
NXP Employee

1. Prepare the environment

pip install tensorflow==2.5.0

2. Install  tf2 Object detect API

Make sure you have protobuf compiler version >= 3.0, by typing protoc --version, or install it on Ubuntu by typing apt install protobuf-compiler.

git clone

# remember to activate your python environment first
cd models/research
# compile protos:
protoc object_detection/protos/*.proto --python_out=.
# Install TensorFlow Object Detection API as a python package:
cp object_detection/packages/tf2/ .
python -m pip install .

3. export tflite graph and convert to quante tflite module.

1) $cd models
2)tar -zxvf ssd_mobilenet_v2_320x320_coco17_tpu-8.tar.gz
3)tar -zxvf convert.tar.gz

3.1   modify
1 model_dir=../ssd_mobilenet_v2_320x320_coco17_tpu-8 <--pre-trained model path 
2 out_dir=$model_dir/exported_tflite
3 mkdir -p $out_dir

3.2  export tflite graph


Use EIQ toolkit  model tool to open the saved model, the input tensor shape is 300x300


3.3  modify

line 3 TEST_DIR       The parent directory of the sample images
line 4  IMAGE_SIZE  The model input tensor shape
line 8 quante              The sample images folder
3.4  run converter script.


4. test performance on imx8mpevk

root@imx8mpevk:/usr/bin/tensorflow-lite-2.5.0/examples# ./label_image -m ~/ssd_mobilenet_v2_quant.tflite -a 1
INFO: Applied NNAPI delegate.
INFO: invoked
INFO: average time: 27.365 ms



Labels (1)
0 Replies