/COMPUTER VISION
Vehicle Detection and Traffic Analysis – YOLOv8m
Custom YOLOv8m computer vision system trained to detect and classify nine road-user categories from real-world Karachi traffic imagery for traffic analysis.

- My role
- Computer Vision / ML Engineer — Solo Project
- Tools & technologies
- Python, YOLOv8, Ultralytics, OpenCV, PyTorch, Roboflow, Computer Vision, Object Detection, Deep Learning, Traffic Analysis, Custom Dataset
- Data
- historical
- Explore
- View GitHub Kaggle Dataset
A look at the project
Overview
Vehicle Detection and Traffic Analysis is a computer vision project focused on detecting and classifying road users in real-world Karachi traffic scenes.
Rather than relying only on a pretrained general-purpose detector, I prepared a custom traffic dataset and trained a YOLOv8m object detection model to recognize vehicle and road-user categories commonly encountered in local traffic.
The project explores how custom object detection can be applied to traffic monitoring and intelligent transportation systems.
Problem
Traffic environments in Karachi contain a diverse mix of road users, including vehicles that may not be represented adequately by generic traffic datasets.
The objective was to build a custom object detection pipeline capable of identifying multiple locally relevant road-user categories from traffic imagery while handling challenges such as congestion, overlapping objects, different vehicle sizes, and varying viewing conditions.
Dataset
I created a custom YOLOv8 traffic dataset containing 997 images at 640 × 640 resolution.
The dataset contains nine classes:
- Bike
- Bus
- Car
- Cart
- Person
- Rickshaw
- Suzuki
- Truck
- Van
Traffic footage was collected from multiple locations in Karachi. Frames were extracted from the recorded footage and prepared for object-detection training.
The dataset was annotated and prepared in YOLO format using Roboflow.
Model Development
YOLOv8m from Ultralytics was used as the object detection architecture.
The workflow included:
- Collecting real-world traffic footage.
- Extracting representative frames from the videos.
- Annotating vehicles and road users.
- Organizing the dataset into YOLO-compatible format.
- Preparing the dataset through Roboflow.
- Training a YOLOv8m model on the custom classes.
- Evaluating detection behavior on unseen traffic scenes.
- Running inference on traffic imagery/video to visualize detections.
Traffic Analysis
The trained detector provides the perception layer required for traffic-analysis applications.
By detecting and distinguishing different road-user categories, its outputs can be used as the foundation for applications such as:
- Vehicle counting
- Traffic-flow analysis
- Congestion monitoring
- Road-user distribution analysis
- Smart-city traffic monitoring
The inclusion of locally relevant categories such as Rickshaw, Suzuki and Cart makes the dataset more representative of Karachi road environments than a generic vehicle-only dataset.
Technical Stack
The project was developed using Python with Ultralytics YOLOv8, PyTorch and OpenCV.
Roboflow was used during the dataset preparation and annotation workflow, while the resulting dataset was structured for YOLO object-detection training.
What I Learned
This project gave me hands-on experience with the complete computer vision lifecycle rather than only model inference.
The work involved collecting data, extracting frames, defining object classes, annotating a custom dataset, preparing YOLO labels, training an object detector and evaluating the resulting model on real traffic scenes.
It also reinforced how strongly the quality, diversity and consistency of training data influence the behavior of an object detection model.
Limitations & context
The model was trained on a relatively small custom dataset of 997 images collected from selected traffic locations in Karachi. As a result, the dataset does not represent every road, weather condition, camera angle, lighting condition or traffic pattern in the city.
Detection performance may decrease under conditions that differ substantially from the training data, including severe occlusion, poor lighting, unusual viewing angles, distant objects or highly congested scenes.
The system should be considered a computer vision prototype and research project rather than a production traffic-monitoring system.
The current work primarily establishes vehicle and road-user detection as the perception layer. More advanced traffic analytics would require additional components such as robust multi-object tracking, calibrated counting zones, temporal analysis and broader validation.




