Image classification (persons, animals, other) on raspberry pi from pi-camera (in live time) using custom model tflite (output to terminal), using TensorFlow Lite

Alex G.
2 min readDec 6, 2020

--

Image classification (persons, animals, other) on raspberry pi from pi-camera (in live time) used custom model tflite
Image classification (persons, animals, other) on raspberry pi from pi-camera (in live time) using custom model tflite (output to terminal) (Photo,GIF by Author) https://github.com/oleksandr-g-rock/image_classification_pi_camera_live_time_custom_model_tflite/blob/main/0_3rpJEUsVESUEAJgP.gif

Short summary:

In this article, I will explain how to create a solution for image classification for the classes (persons, animals, others) on Raspberry Pi from Pi-camera in live time.
I will use a custom model tflite which I converted from h5.
And all results will be shown in the terminal. Code for this article is available here.

Note before you start:

So, let's start :)

Hardware preparation:

Software preparation:

1. Create a neural network model to predict 3 classes: persons, animals, others.

I have already done it in the article below. So in this article, you do not need to do this.

2 Convert h5 model to tflite model

I have already done it in the article below. So in this article, you do not need to do this.

3 So, let’s try to predict class from camera raspberry pi in live time with output to the terminal using Tensorflow Lite and custom model tflite (which I trained and saved above).

For that, you need to run the next code:

#clone my repo
git clone https://github.com/oleksandr-g-rock/image_classification_pi_camera_live_time_custom_model_tflite.git
#go to folder
cd image_classification_pi_camera_live_time_custom_model_tflite
#download tflite model
wget https://github.com/oleksandr-g-rock/how_to_convert_h5_model_to_tflite/raw/main/animall_person_other_v2_fine_tuned.tflite
#run script
python3 classify_picamera_with_live_time_custom_tflite_model.py

4 You should see something like that.

Image classification (persons, animals, other) on raspberry pi from pi-camera (in live time) using custom model tflite (output to terminal) (Photo,GIF by Author) https://github.com/oleksandr-g-rock/image_classification_pi_camera_live_time_custom_model_tflite/blob/main/0_3rpJEUsVESUEAJgP.gif

Result:

In this article, we created a solution for image classification for the classes (persons, animals, others) on Raspberry Pi from Pi-camera in live time.
I will use a custom model tflite which I converted from h5.
And all results will be shown in the terminal. Code for this article is available here.

--

--

Alex G.

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