This project is a real-time vehicle detection system built using Ultralytics YOLO. It identifies and classifies different types of vehicles in both live webcam feeds and pre-recorded videos.
The model was custom-trained on a dataset I created from scratch using real-world traffic footage. I manually labeled thousands of images to build a dataset tailored for detecting five specific vehicle categories: Ambulance, Bus, Car, Motorcycle, and Truck. This helped the model perform accurately in real-world urban scenarios.
- 📹 Real-time detection via webcam or video file
- 🎯 Custom-trained YOLO model with 5 vehicle classes
- 📦 Bounding boxes with labels drawn on detected vehicles
- 💾 Outputs saved with annotated video frames
- 🛠️ CLI interface for flexible usage
| ID | Class Name |
|---|---|
| 0 | Ambulance |
| 1 | Bus |
| 2 | Car |
| 3 | Motorcycle |
| 4 | Truck |
video1.mp4
video3.mp4
git clone https://github.com/yourusername/vehicle-detection.git
cd vehicle-detectioncurl -o yolo_detect.py https://raw.githubusercontent.com/EdjeElectronics/Train-and-Deploy-YOLO-Models/refs/heads/main/yolo_detect.pyVisit pytorch.org to install the correct version for your system.
Example for M2 Pro MacBook:
pip3 install torch torchvision torchaudiopython3 yolo_detect.py --model my_model.pt --source <path_to_video_file> --resolution 1920x1080python3 yolo_detect.py --model my_model.pt --source usb0 --resolution 1920x1080