The project was the result of experimenting with machine learning with the end goal of deploying something onto a Raspberry Pi. The reason for birds is just that it was the first and easiest to use free dataset that I could also realistically test with a camera.
- TensorFlow (and TFlite)
- YOLOv5 (Pytorch)
- Docker
The Jupyter notebook (makeMode.ipynb) contains all necessary commands to retrieve and prepare the Caltech 2011 Birds dataset for YOLOv5.
I originally created it in Google Colab and that is where many of the image producing and plotting functions work correctly, but the functionality works across a variety of Jupyter notebook platforms.
Due to the size of the dataset and time required to train the model, I first looked into training the model on my local computer using Docker. The docker system works and can be easily modified to run with a local Nvidia GPU, but I don't have one, and CPU training times are unusably long. However, VSCode's devcontainer features worked really well with this Docker.
One note about Docker: local systems often have issues with Yolov5's workers. Disable them with --workers 0
. CPU training can be similarly configured with --device cpu
.
I chose Saturn cloud as an alternative to Colab for training my model. The 30 hours of free GPU time per month are more than enough to train with a couple hundred epochs.
The deployment folder contains everything necessary for deploying this model on a Raspberry Pi with a USB webcam as I did. It contains some trained models as well. I run mine in a python virtual environment with
python3 bw-deploy.py -m best-fp16.tflite
To cleanly exit, hit q
while on the window with the image. CTRL-C
has a tendency to get the camera stuck.
OpenCV requires a bunch of packages and will give you weird errors until you install them all with apt-get. I tested this on an older Pi running Python 3.5 and was able to get all the packages.
If you see VIDIOC_QBUF: Invalid argument
, this is a weird webcamera/threading issue that comes up. I've just been restarting my Pi and it goes away.