Overview
Deploying YOLO-Pi in a production environment requires careful consideration of reliability, monitoring, security, and performance. This guide covers essential practices for running YOLO-Pi at scale.Architecture Considerations
System Components
A production YOLO-Pi deployment typically consists of:- YOLO-Pi Container(s): Running object detection on camera feeds
- MQTT Broker: Message broker for publishing detection events
- Backend Services: Consuming and processing detection data
- Monitoring Stack: Tracking performance and health
YOLO-Pi publishes detection results to an MQTT topic called
yolo with JSON payloads containing detected objects and confidence scores.MQTT Broker Setup
YOLO-Pi requires an MQTT broker to publish detection results. The application connects to the broker specified in theMQTT environment variable.
Installing Mosquitto
Container Orchestration
Using Docker with Systemd
For single-node deployments, use systemd to manage the YOLO-Pi container:Create systemd service file
Create
/etc/systemd/system/yolo-pi.service:Service file breakdown
Service file breakdown
Requires=docker.service: Ensures Docker is runningAfter=mosquitto.service: Starts after MQTT brokerRestart=always: Auto-restart on failureRestartSec=10: Wait 10 seconds between restartsExecStartPre: Remove old container if exists--rm: Clean up container on stop
Using Docker Compose
For multi-container setups, use Docker Compose:docker-compose.yml
Monitoring and Logging
Container Logs
View real-time logs:- MQTT connection status
- Model loading confirmation
- Detection results with timestamps
- Error messages
Log Rotation
Configure Docker log rotation in/etc/docker/daemon.json:
Health Monitoring
Monitor MQTT messages to detect issues:Resource Monitoring
Monitor container resource usage:On Raspberry Pi 3, expect:
- CPU: 80-100% (during processing)
- Memory: 400-600MB
- Processing rate: ~0.5 FPS (1 frame per 2 seconds)
Performance Optimization
Model Selection
YOLO-Pi supports different YOLO models. Choose based on your requirements:| Model | Speed | Accuracy | Use Case |
|---|---|---|---|
| tiny-yolo-voc | Fast (~0.5 FPS on RPi3) | Lower | Production on Raspberry Pi |
| yolo-voc | Slow | Medium | Testing on x86 |
| yolo-coco | Very slow | High | Development only |
/app/yolo-pi.py:
Detection Threshold
Adjust score and IOU thresholds inyolo-pi.py:154-158:
Threshold tuning
Threshold tuning
- score_threshold: Minimum confidence (0.0-1.0). Higher = fewer false positives, more missed detections
- iou_threshold: Intersection over Union for non-max suppression. Higher = more overlapping boxes allowed
score_threshold=0.5 to reduce noise.Hardware Optimization
Raspberry Pi:- Use active cooling (fan or heatsink)
- Quality power supply (2.5A minimum)
- Overclock (if stable): Edit
/boot/config.txt - Use Camera Module instead of USB (lower latency)
- Enable GPU acceleration (requires CUDA-enabled TensorFlow)
- Use AVX2-optimized builds
- Increase worker threads
Security Considerations
MQTT Authentication
Disable anonymous access and require authentication:Network Security
Best practices:- Run MQTT broker on internal network only
- Use firewall rules to restrict access
- Enable TLS for MQTT (port 8883)
- Use VPN for remote access
- Never expose MQTT broker directly to the internet
Container Security
Some capabilities may be required for camera access. Test thoroughly when implementing security restrictions.
Backup and Recovery
Backup Configuration
Backup critical files:Disaster Recovery
Restore from backup:Scaling Considerations
Multiple Cameras
Run multiple containers for multiple cameras:Each container maps its respective camera to
/dev/video0 internally. Modify the MQTT client ID in yolo-pi.py to distinguish between cameras.Distributed Deployment
For multiple Raspberry Pi devices:- Centralize MQTT broker on a server
- Configure each Pi with the broker’s IP
- Use unique client IDs (modify
yolo-pi.py:23) - Subscribe to
yolo/#with wildcards to capture all devices
Troubleshooting Production Issues
Container keeps restarting
Container keeps restarting
Check logs for errors:Common causes:
- MQTT broker unreachable
- Camera device not available
- Out of memory (check with
docker stats)
No MQTT messages received
No MQTT messages received
Verify:
- Container is running:
docker ps - MQTT broker is accessible:
mosquitto_sub -h <broker-ip> -t yolo - Camera is working: Check container logs
- No firewall blocking port 1883
High CPU usage
High CPU usage
This is normal for YOLO-Pi. To reduce:
- Lower camera resolution
- Reduce frame rate (modify
yolo-pi.py) - Use a more powerful device
- Consider hardware acceleration
Detection accuracy is poor
Detection accuracy is poor
Improve accuracy:
- Ensure adequate lighting
- Clean camera lens
- Increase
score_thresholdto 0.5+ - Use full YOLO model instead of tiny-yolo (on x86)
- Train custom model on your specific use case
Next Steps
Running Inference
Learn how to run and configure inference
API Reference
Explore the YOLO-Pi API

