Overview
Deploying YOLO-Pi on Raspberry Pi requires building an ARM-compatible Docker image with TensorFlow support. This process is resource-intensive and requires special preparation.Prerequisites
- Raspberry Pi 3 (or newer) with Raspbian Stretch
- 2GB+ USB drive for swap space
- Camera module or USB camera
- At least 8GB SD card with 2-3GB free space
- Stable internet connection
Setting Up Swap Space
Raspberry Pi’s limited RAM requires additional swap space to compile the Docker image.Prepare USB drive
Insert a 2GB+ USB drive and identify it (usually Create a partition and format it:
/dev/sda):Configure automatic mounting
Edit Add this line:Mount all filesystems:
/etc/fstab to mount the USB drive on boot:Configure swap file
Edit the swap configuration:Comment out existing
CONF_SWAPFILE and CONF_SWAPSIZE lines and add:Building the Docker Image
Start a screen session
Use screen to prevent interruption if SSH disconnects:
To detach from screen: Press
Ctrl+A, then DTo reattach: screen -r docker-buildPrepare build directory
Create a build directory and copy the Dockerfile:Copy
Dockerfile.rpi to this directory as Dockerfile.Download TensorFlow wheel
Download the pre-compiled TensorFlow binary for ARM and rename it:
Why rename the wheel?
Why rename the wheel?
The Dockerfile uses Python 3.5 (
cp35), but the pre-compiled wheel is tagged for Python 3.4 (cp34). Renaming allows pip to install it for Python 3.5.Build the Docker image
Start the build process:The build process:
- Installs system dependencies
- Installs NumPy, Keras 2.1.2, h5py, and paho-mqtt
- Installs TensorFlow 1.1.0 from the wheel file
- Compiles OpenCV 3.3.0 from source
- Copies application code
Running on Raspberry Pi
Interactive Mode
Run interactively for testing:Daemon Mode
Run as a background service:Command options explained
Command options explained
-d: Run in detached (daemon) mode--device /dev/video0: Grant access to camera-e MQTT=<mqtt-server-ip>: Set MQTT broker address--restart unless-stopped: Auto-restart on failure or reboot--name yolo-pi: Name the container for easy management
Running Automatically on Boot
Create container with restart policy
Use the
--restart unless-stopped flag when creating the container:Managing the Container
View logs
Stop the container
Start the container
Restart the container
Remove the container
Performance Considerations
YOLO-Pi on Raspberry Pi 3 processes approximately 1 frame every 2 seconds using the tiny-yolo-voc model. This is expected behavior given the hardware constraints.
Optimization Tips
- Use the
tiny-yolo-vocmodel (smaller and faster than full YOLO) - Reduce camera resolution if needed
- Ensure adequate cooling (heatsinks or fan)
- Use a high-quality power supply (2.5A minimum)
Troubleshooting
Build runs out of memory
Build runs out of memory
Ensure swap is properly configured and active:You should see 2GB of swap space. If not, repeat the swap setup steps.
Build fails during OpenCV compilation
Build fails during OpenCV compilation
This is often due to insufficient resources. Ensure:
- Swap space is active (2GB)
- No other heavy processes are running
- SD card has at least 2GB free space
Camera not accessible
Camera not accessible
For Raspberry Pi Camera Module, ensure it’s enabled:For USB cameras, verify the device:
TensorFlow wheel installation fails
TensorFlow wheel installation fails
Ensure you’ve renamed the wheel file correctly to match Python 3.5. The filename must be exactly:
Image Details
The Raspberry Pi Docker image includes:- Base Image:
resin/rpi-raspbian:stretch - OpenCV: 3.3.0 compiled for ARM (without AVX/CUDA)
- TensorFlow: 1.1.0 (pre-compiled ARM wheel)
- Keras: 2.1.2
- MQTT Client: paho-mqtt
- Additional Libraries: NumPy, h5py 2.7.1, scipy, PIL
Next Steps
Production Setup
Learn about production deployment best practices
Running Inference
Learn how to run and configure inference

