Create FAST recognition object detection in the live time on the Raspberry Pi + OpenCV + TensorFlow Lite
Short summary:
In the previous article, I created simple object detection in live time. Link below:
But in the article (which above) — the speed for object detection was near ~2 FPS
It’s REALLY SLOW. So in this article, I show you how to improve speed for object detection to ~4.5FPS.
Note before you start:
So, Let’s start :)
Hardware preparation:
Software preparation:
1 preparing VNC (if you have)
If you go to VNC Server Options (right-click on the VNC status icon in the top right) and check to Enable direct capture mode on the Troubleshooting page. This will allow you to see the camera output via VNC. Like on the screenshots:
2 install special version opencv-contrib-python==4.1.0.25
python3 -m pip install opencv-contrib-python==4.1.0.25
3 Check python version, it should be 3.7
python3 --version
4 Download Tensorflow Lite from here
python3 -m pip install https://github.com/google-coral/pycoral/releases/download/release-frogfish/tflite_runtime-2.5.0-cp37-cp37m-linux_armv7l.whl
5 Create directory
mkdir -p ~/tflite/object_detection/coco_ssd_mobilenet_v1
cd ~/tflite/object_detection
6 Download Pre-Trained Model
wget https://storage.googleapis.com/download.tensorflow.org/models/tflite/coco_ssd_mobilenet_v1_1.0_quant_2018_06_29.zip
7 Unzip Pre-Trained Model
unzip coco_ssd_mobilenet_v1_1.0_quant_2018_06_29.zip -d coco_ssd_mobilenet_v1
8 Run object detection script
User EdjeElectronics has example python script for object detection TFLite_detection_webcam.py and these code is based off the TensorFlow Lite image classification example at here. So just run this script for run fast object detection.
wget https://raw.githubusercontent.com/EdjeElectronics/TensorFlow-Lite-Object-Detection-on-Android-and-Raspberry-Pi/master/TFLite_detection_webcam.py && python3 TFLite_detection_webcam.py --modeldir=coco_ssd_mobilenet_v1
9 You should see something like that
Result:
In this article, we created FAST recognition object detection in the live time on the Raspberry Pi. We improved speed o x2. So I guess it’s a good result.