Simple image classification (persons, animals, other) on raspberry pi using custom model tflite (output to terminal) dividing image into 4 parts using OpenCV and TensorFlow Lite
Short summary:
In this article, I will explain how to create image classification (persons, animals, other) on raspberry pi using custom model tflite (output to terminal) dividing image into 4 parts using OpenCV and TensorFlow Lite. 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 IT.
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 IT.
3 I want to divide this image into 4 parts using OpenCV
For your information, I explained how I did it in this article:
4 Predict class for each part of this divided image
So, let’s implement our model to image classification (persons, animals, other) on raspberry pi using custom model tflite (output to terminal) dividing image into 4 parts using OpenCV and TensorFlow Lite
For that, you need to run the next code:
#clone my repo
git clone https://github.com/oleksandr-g-rock/simple-image-classification-4-divide-image-tflite.git#go to folder
cd simple-image-classification-4-divide-image-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 image_classify_divided_image.py
5 You should see something like that.
So this model predicted the absolutely right class for each part of image.
Because output was:
IMAGE R4. ... class name: animals
IMAGE L2. ... class name: other
IMAGE L1. ... class name: animals
IMAGE R3. ... class name: person
Result:
In this article, we created a solution for image classification (persons, animals, other) on raspberry pi using custom model tflite (output to terminal) dividing image into 4 parts using OpenCV and TensorFlow Lite. Code for this article is available here.