This project focuses on path segmentation using YOLOv8 (segmentation) and its systematic optimization for real-time deployment on embedded hardware (Raspberry Pi 5).
The work demonstrates a complete model-to-deployment pipeline:
- Dataset preparation and binary mask annotation (289 images)
- Training a YOLOv8n-seg model for path segmentation
- Performance benchmarking at multiple input resolutions
- Model optimization via ONNX conversion
- Real-time inference validation on Raspberry Pi 5 (CPU only)
- Quantitative analysis of speed–accuracy trade-offs
Key Achievement After optimization, the model achieves 15.4 FPS (64.8 ms latency) on Raspberry Pi 5 CPU, enabling real-time robotic path-following without GPU acceleration.
Initial experiments showed that although the trained YOLOv8 segmentation model produced accurate path detection on static images, it failed during real-time inference on embedded hardware.
Observed Issues
- 640×640 inference → ~2.9 FPS (≈349 ms latency) ❌
- Unstable control loop due to high latency
- CPU-only inference on Raspberry Pi 5 was a bottleneck
- Real-time deployment was not feasible initially
Through benchmark-driven optimization, the following improvements were achieved:
- Identified 320×320 as the optimal resolution
- Converted model from PyTorch (.pt) to ONNX (.onnx)
- Achieved 1.57× speedup
- Final performance: 15.4 FPS @ 320×320
This proves that embedded real-time vision is achievable on low-cost hardware with proper optimization.
YOLOv8-Path-Segmentation-RealTime-Optimization/
│
├── Dataset/
│ ├── Images/ # 289 path images
│ └── Masked_Images/ # Binary segmentation masks
│
├── Models/
│ ├── best.pt # Trained YOLOv8n-seg model
│ └── best_320.onnx # Optimized ONNX model
│
├── Notebooks/
│ └── training_yolov8_segmentation.ipynb
│
├── Optimization/
│ ├── export_onnx.py
│ └── optimized_inference_example.py
│
├── Benchmarks/
│ └── benchmark_model.py
│
├── Results/
│ ├── test_images/
│ ├── inference_results/
│ └── benchmark_results/
│ ├── fps_vs_resolution_pytorch.png
│ ├── pytorch_vs_onnx_fps.png
│ └── validation_metrics.png
│
├── requirements.txt
└── README.md
- Architecture: YOLOv8n-seg
- Task: Binary path segmentation
- Classes: 1 (
path) - Framework: Ultralytics YOLOv8
- Training Image Size: 640×640
- Parameters: ~3.2 M (nano model)
- Platform: Google Colab (Tesla T4 GPU)
- Epochs: 200
- Batch Size: 8
- Optimizer: Adam
- Data Augmentation: YOLOv8 default augmentations
- Dataset Size: 289 images
- Train / Validation Split: ~80 / 20
Precision (Mask): 0.9648
Recall (Mask): 0.9632
mAP@50 (Mask): 0.9883
mAP@50-95 (Mask): 0.7365
These results confirm high segmentation accuracy despite later resolution reduction.
- Source: Custom-captured path images
- Camera: Logitech Brio 100
- Path Type: Red tape on floor
- Environment: Indoor laboratory conditions
- Annotation: Binary masks (path vs background)
Total Samples: 289 Annotation Quality: Manually verified
- Device: Raspberry Pi 5
- Inference Mode: CPU only
- Frameworks: PyTorch & ONNX Runtime
- Test Method: 20 inference runs (warm-up excluded)
| Resolution | Avg Time | FPS | Status |
|---|---|---|---|
| 640×640 | 349.5 ms | 2.9 | ❌ Too slow |
| 480×480 | 201.3 ms | 5.0 | ❌ Too slow |
| 320×320 | 103.0 ms | 9.7 |
| Format | Avg Time | FPS | Speedup |
|---|---|---|---|
| PyTorch (.pt) | 101.6 ms | 9.8 | 1.0× |
| ONNX (.onnx) | 64.8 ms | 15.4 | 1.57× ✅ |
ONNX optimization enabled stable real-time inference.
Steps applied:
- Baseline benchmarking with PyTorch model
- Resolution tuning (640 → 320)
- Export to ONNX with fixed input size
- Re-benchmark on target hardware
Export Code Used
from ultralytics import YOLO
model = YOLO("best.pt")
model.export(
format="onnx",
imgsz=320,
simplify=True,
dynamic=False
)Sample inference outputs are stored in:
Results/inference_results/
They show:
- Accurate path segmentation
- Stable predictions under real-time conditions
- Correct mask alignment with the physical path
- High-resolution inference is unsuitable for embedded CPUs
- ONNX significantly reduces inference latency
- 320×320 offers the best speed-accuracy balance
- Real-time segmentation is feasible on Raspberry Pi 5
This project demonstrates that YOLOv8 segmentation models can be successfully deployed on embedded hardware using systematic optimization.
By combining:
- Resolution tuning
- ONNX conversion
- Hardware-aware benchmarking
we achieved real-time performance (15.4 FPS) without sacrificing segmentation quality.
Satwik Shreshth Dissertation Intern CSIR – Central Mechanical Engineering Research Institute (CSIR-CMERI) Micro Robotics Laboratory Year: 2026
This project is intended for academic and research purposes.
⭐ If you find this project useful, please consider starring the repository.