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 https://github.com/tensorflow/models.git
# 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/setup.py .
python -m pip install .
3. export tflite graph and convert to quante tflite module.
1) $cd models
$wget http://download.tensorflow.org/models/object_detection/tf2/20200711/
ssd_mobilenet_v2_320x320_coco17_tpu-8.tar.gz
2)tar -zxvf ssd_mobilenet_v2_320x320_coco17_tpu-8.tar.gz
3)tar -zxvf convert.tar.gz
3.1 modify export_tflite.sh
export_tflite.sh
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
./export_tflite.sh
Use EIQ toolkit model tool to open the saved model, the input tensor shape is 300x300
3.3 modify convert.py
python convert.py
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