How can we easily do custom object detection on Raspberry pi?? Let’s try these few easy ABC steps with the videoguide and colab!
A. INSTALLATION PROCEDURE ON RASPBERRY PI 5 (see videoguide)
- Key in the following commands
sudo rm /usr/lib/python3.11/EXTERNALLY-MANAGED
sudo apt update
sudo apt upgrade
sudo pip3 install opencv-python
sudo pip3 install torch==2.0.1 torchvision==0.15.2 torchaudio==2.0.2
sudo pip3 install ultralytics
sudo pip3 install cvzone
sudp pip3 install mediapipe
2. Download the best.pt after running colab into the bookwork folder
Let’s answer a couple of questions when we run the YOLOv8 custom detection from Colab.
B. RUN THE CUSTOM YOLOV8 MODEL (see Colab)
To get ourselves familiar with colab, let’s answer the following questions.
- where is the location of custom weights
It is under runs/train/weights/best.pt
2. what is dataset format when we deploy from Roboflow
all the 3 folders — train, test, valid — have the similar images and labels folder below.
C. DOWNLOAD GITHUB TO RASPBERRY PI (see github below)
1. Where do we paste the best.pt in Raspberry Pi?
Paste it directly in the working folder
2. Which line do we need to modify?
Open the cam.py file and save as yourname.py.
Change YOLO(‘yolosn.pt’) to YOLO(‘best.pt’).
3. Which files do we need to modify?
Modify the “coco.txt” to “coco1.txt” by adding the classes of the foot ball players.
4. How do we run the camera file?
Look for the cam.py file and use Thonny and press the play button
D. VERIFY THE RESULTS OF DETECTION
It is able to detect the small ball — yes! This means the object detection is successful
One thing we notice is that the FPS is very jittery. So the additional work will be to add the FPS code into the cam.py file.
Resource:
Videoguide:https://www.youtube.com/watch?v=XzhTq-nk8GQ
Colab:https://www.youtube.com/watch?v=XzhTq-nk8GQ
Github:https://github.com/freedomwebtech/rpi-bookworm-yolov8