Object detection with YOLO
Detect and count objects (for example vehicles or helmets) in images and video, and train on your own labelled data.
Advancedโฑ 12โ18 hours๐ช 7 stepsPythonUltralytics YOLOOpenCV
What you'll learn
- โHow object detection differs from classification
- โLabelling data and the YOLO format
- โmAP and inference speed
What you'll build
- โPretrained detection on video
- โLine-crossing counter
- โCustom training on your dataset
- โmAP report
Step-by-step guide
- 1
Try a pretrained model
pip install ultralytics; from ultralytics import YOLO; YOLO("yolov8n.pt").predict("traffic.mp4", show=True).
- 2
Count objects
Use tracking (model.track) and count IDs that cross a line you draw.
- 3
Choose a custom task
For example helmet / no-helmet; collect 300+ images.
- 4
Label
Use a labelling tool (Label Studio, CVAT or Roboflow) and export in YOLO format.
- 5
Train
Write data.yaml (paths, class names) and run model.train(data="data.yaml", epochs=50, imgsz=640).
- 6
Evaluate
Check mAP50 and mAP50-95 on the validation set; look at failure images.
- 7
Deploy
Export to ONNX and measure FPS on a laptop CPU.
๐ Make it stand out
- +Alert when a rider without a helmet is detected
- +Run on a Raspberry Pi
- +Speed estimation