To get the best performance (speed + accuracy) for your specific hallway, you should fine-tune the model. Using the default model finds everything (cars, dogs, umbrellas), but you only care about people.
We will teach the model to ignore everything except humans and focus specifically on the camera angle of your hallway.
- Higher Accuracy: The model learns your specific lighting and background.
- Faster Post-Processing: By training for only 1 class ('person'), the Pi does less math filtering out other objects.
Capture images from your actual deployed camera.
- Create a folder:
mkdir -p dataset/images - Run a simple script to save a frame every 5 seconds (or use
crowd_counting_rpi.pyand manually save interesting frames). - Aim for: 100-200 images of people walking in your hallway. Varied clothing and lighting helps.
Label your images.
- Move images to your PC.
- Use a tool like Roboflow (easiest, web-based) or CVAT.
- Draw boxes around every person.
- Export Dataset: Choose "YOLOv8" format (compatible with YOLO11).
- Open Google Colab.
- Select Runtime > Change runtime type > T4 GPU.
- Run this code:
# 1. Install Ultralytics
!pip install ultralytics
# 2. Upload your dataset zip file from Roboflow/CVAT
# (Unzip it into a folder called 'datasets')
# 3. Train the model
from ultralytics import YOLO
# Load the nano model
model = YOLO('yolo11n.pt')
# Train
results = model.train(
data='/content/datasets/data.yaml', # Path to your dataset config
epochs=50, # 50-100 is usually enough for fine-tuning
imgsz=640, # Maintain resolution
device=0, # Use GPU
project='hallway_monitor',
name='v1'
)- Download the trained
best.ptfile from Colab. - Transfer it to your Raspberry Pi.
- Export for NCS2 (Critical Step):
yolo export model=best.pt format=openvino half=True - Update your
crowd_counting_rpi.pyto use your new model path or pass it via command line:python3 crowd_counting_rpi.py --model best_openvino_model/
Since you are using Intel NCS2, you are already using FP16 (Half Precision). For further speed (at cost of some accuracy), you can explore INT8 Quantization with the OpenVINO toolkit, but this is complex and usually not needed if you stick to the Nano (n) model.