Simple image classification on raspberry pi from pi-camera (in live time) using the pre-trained model mobilenet_v1 and TensorFlow Lite

Alex G.
2 min readNov 18, 2020
Simple image classification on raspberry pi from pi-camera (in live time) using the pre-trained model mobilenet_v1 and TensorFlow Lite (Photo,GIF by Author) https://github.com/oleksandr-g-rock/simple_object_detection/blob/main/1_hd7sGxFw7fwPRoCiDQXvSQ.gif

Short summary:

In this article, I will explain, how to create simple image classification on raspberry pi from pi-camera (in live time) using the pre-trained model mobilenet_v1 and TensorFlow Lite. In this example, I will use the pre-train model mobilenet_v1, but you can try to use any pre-train model. All code is located here.

Note before you start:

So, Let’s start :)

Hardware preparation:

Software preparation:

1 Try predict class from camera raspberry pi in live time using Tensorflow Lite.

For that, you need to run the next code:

#install tensorflow lite
pip3 install https://github.com/google-coral/pycoral/releases/download/release-frogfish/tflite_runtime-2.5.0-cp37-cp37m-linux_armv7l.whl
git clone https://github.com/tensorflow/examples --depth 1cd examples/lite/examples/image_classification/raspberry_pi# The script takes an argument specifying where you want to save the model files
bash download.sh /tmp

2 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:

(Photo,GIF by Author) https://github.com/oleksandr-g-rock/simple_object_detection/blob/main/0_BvOkcWvUyTXTW8gY.png
(Photo,GIF by Author) https://github.com/oleksandr-g-rock/simple_object_detection/blob/main/0_FhS-AYQn0gmWw6hC.png

3 After that run script in terminal

python3 classify_picamera.py \
--model /tmp/mobilenet_v1_1.0_224_quant.tflite \
--labels /tmp/labels_mobilenet_quant_v1_224.txt

4 You should see something like that.

Simple image classification on raspberry pi from pi-camera (in live time) using the pre-trained model mobilenet_v1 and TensorFlow Lite (Photo,GIF by Author) https://github.com/oleksandr-g-rock/simple_object_detection/blob/main/1_hd7sGxFw7fwPRoCiDQXvSQ.gif

Result:

In this article, we created simple image classification on raspberry pi from pi-camera (in live time) using the pre-trained model mobilenet_v1 and TensorFlow Lite. In this example, I using the pre-train model mobilenet_v1, but you can try to use any pre-train model. All code is located here.

--

--

Alex G.
Alex G.

Written by Alex G.

ML DevOps engineer. 🙂 I am always open to new opportunities and offers. 🖖 I trying to help the world 🌏 with machine learning.

No responses yet