Vehicle Classification with YOLOv8
Robust detection of 6 vehicle classes for smart traffic monitoring
Abstract
In the context of intelligent transportation systems, accurate vehicle detection and classification are paramount for traffic flow analysis and automated toll collection. This project presents a deep learning-based object detection pipeline leveraging the YOLOv8 architecture to classify six distinct categories of vehicles commonly found in South Asian and Southeast Asian traffic: Car, Threewheel, Bus, Truck, Motorbike, and Van.
By utilizing a balanced dataset and employing transfer learning on the YOLOv8 Small (yolov8s.pt) model, the system achieves an excellent trade-off between inference speed and mean Average Precision (mAP@50), demonstrating strong generalization across diverse traffic conditions.
Methodology
1. Dataset Description
The model was trained on a comprehensive vehicle dataset sourced from Kaggle (nadinpethiyagoda/vehicle-dataset-for-yolo). The dataset was carefully curated to ensure balanced representation across the 6 target classes. This diversity, particularly the inclusion of "Threewheel" (tuk-tuks) alongside standard vehicles, makes the model highly applicable to real-world traffic scenarios in developing regions.
2. Model Choice: YOLOv8 Small
The YOLOv8 Small (YOLOv8s) model was selected as the core architecture. Ultralytics' YOLOv8 represents the state-of-the-art in real-time object detection, offering significant improvements in accuracy and speed over its predecessors. The Small variant was specifically chosen because it provides an optimal balance: it is lightweight enough to run in real-time on edge devices (such as traffic cameras or Jetson Nanos) while maintaining a high mAP, which is crucial for distinguishing between visually similar classes like Cars and Vans in crowded scenes.
3. Training Configuration
- Epochs: 100 with an early stopping patience of 20 epochs.
- Image Size: 640x640 resolution to capture small distant vehicles.
- Batch Size: 16, optimized for standard GPU memory constraints.
Quantitative Evaluation
The model achieved an exceptional overall mAP@50 of 98.3%. Notably, it also recorded an average inference speed of 6.7ms per image on a Tesla T4 GPU, demonstrating its high efficiency.
| Class | mAP@50 |
|---|---|
| All Classes | 0.983 |
| Car | 0.964 |
| Threewheel | 0.994 |
| Bus | 0.992 |
| Truck | 0.984 |
| Motorbike | 0.971 |
| Van | 0.993 |
Inference Results
The following images demonstrate the model's performance on unseen data from the validation set. Bounding boxes indicate the detected vehicle class along with the confidence score. The model successfully detects multiple overlapping vehicles, handles varying scales, and accurately identifies the Threewheel class.










Interactive Demo
You can test the trained model (yolov8s_smart_traffic_best.pt) live using the interactive space below. Upload your own image of traffic or vehicles to see the YOLOv8 model perform classification and bounding box detection in real-time.
Challenges & Limitations
- Data Imbalance: Since cars form the overwhelming majority of vehicles on the road, it took a considerable amount of time to manually select and curate a perfectly balanced dataset. This careful curation was necessary to prevent the model from biasing toward Cars and to ensure sufficient representation of minority classes like the Threewheel and Van.
- Overlapping Vehicles: In dense traffic scenarios, vehicles frequently occlude one another. While YOLOv8 handles occlusion well, small or heavily obscured vehicles in the background occasionally suffer from lower confidence scores.
- Computational Resource Limits: Training on high-resolution images (640x640) for 100 epochs requires significant VRAM. Optimizing the batch size (16) was a necessary step to ensure the training could be completed smoothly within standard GPU constraints (like Kaggle/Colab).
Conclusion
The YOLOv8 pipeline demonstrates robust vehicle classification capabilities across 6 distinct classes. Its ability to maintain high precision even with classes like the Threewheel makes it a highly viable solution for intelligent traffic monitoring systems in diverse environments. Furthermore, this YOLOv8 Small model achieves not only exceptional accuracy but also meets rigorous low-latency inference standards (~6.7ms). This makes it highly deployable for real-time live-streaming endpoints, as demonstrated by the Interactive Demo above.