Computer Vision (TensorFlow Lite)
program that can find patterns or make decisions from a previously unseen dataset.
Main steps
1 - Video/Roboflow: Gather images for dataset
2 - Colab: Train Custom Model
3 - Export Model
4 - Set up Pi
5 - Run on Pi
1 - Video/Roboflow: Gather images for dataset
We can film a video of the item we want to detect and then upload to Roboflow. On the Roboflow website, we can extract frames every X seconds to create a .jpg file each interval. Then we can begin labeling each image on Roboflow.
Roboflow is a website where you upload images, label them, and export a zip file (images & .xml files).
Useful to share dataset and have 3 people label at the same time
1.1 - Unlabeled Images to Labeled Images
2 - Colab: Train Custom Model
-The following website uses Python
-here we set up libraries
- collections of pre-written code that you
can use to perform specific tasks
-Prepare the dataset
-Train the model
-Evaluate the model performance with validation data
-Export the model as .tflite file
Open up this pre-made online coding website called Google Colab
3 - Export Model
We can export the custom model after training as a .tflite file which will be uploaded to the Raspberry Pi and then can be used for Object Detection. Demo here
4 - Set up Pi
numpy >= 1.20.0
opencv-python~=4.8.0
tflite-support>=0.4.2
protobuf>=3.18.0,<4
NOTE:: - python 3.7.3
numpy 1.23
opencv-python-4.9.0.80
tflite-support==0.4.2
pip install protobuf==3.20.*
NOTE:: - Python 3.9.18
- pip install ipykernel
- conda create -n myenv python=3.9 -y
- pip 23.3.1
- pycocotools-2.0.7
Installation
NOTE: (2:54)
-click top left
-preferences
-raspberry pi configuration
-tabs: interfaces
-enable camera
-reboot
NOTE: -click top left
-preferences
-raspberry pi configuration
-tabs: interfaces
-enable camera
-reboot
(3:26) sudo apt-get update
python3 --version
NOTE:: python 3.7.3
python3 -m pip install --user --upgrade pip
python3 -m pip install --user virtualenv
python -m venv ~/tflite
source ~/tflite/bin/activate
git clone https://github.com/tensorflow/examples.git
cd examples/lite/examples/object_detection/raspberry_pi
sh setup.sh
python detect.py
sudo apt-get install python3-tflite-runtime
git clone https://github.com/tensorflow/examples.git --depth 1
cd example/object_detection/raspberrypi/
NOTE: change opencv version
nano requirements.txt
opencv-python~=4.8.0
#from tflite official pg bash setup.sh
pip install protobuf==3.20.*
python -m pip install --upgrade tflite-support==0.4.2 #didnt download
python -m pip install --upgrade tflite-runtime==2.11.0 #didnt download
pip install numpy==1.23
(33:16) opens detect.py-in thonny and then edits custom model and then runs it to detect #Python 3.10.12
5 - Run on Pi
source tflite/bin/activate
cd examples/lite/examples/object_detection/raspberry_pi/
cp ~/Downloads/android.tflite .
python detect.py
python detect.py --model android.tflite
Sources
[1] Tensorflow Videob (The Colab they have doesn't work with newer Python versions)
Last updated