This project harnesses the power of YOLOv8's real-time detection capabilities to tackle Traffic Density Estimation, a crucial aspect of urban and traffic management systems. The primary objective is to accurately count vehicles within designated areas in video frames to evaluate traffic flow. The insights garnered from this data are instrumental in pinpointing peak traffic times, identifying bottlenecks, and aiding urban planning. We have crafted an extensive toolkit that provides in-depth analysis of traffic patterns, thereby augmenting traffic control and city planning endeavors.
The pivotal milestones achieved in our project include:
- YOLOv8 Model Selection and Assessment: Commencing with the selection of a pre-trained YOLOv8 model and evaluating its baseline performance on the COCO dataset for vehicle detection purposes.
- Specialized Vehicle Dataset Curation: Assembling and annotating a targeted dataset dedicated to vehicles to enhance the model's detection accuracy for a range of vehicle types.
- Model Refinement for Superior Detection: Applying transfer learning techniques to fine-tune the YOLOv8 model, with a special focus on detecting vehicles from aerial views, thus significantly improving precision and recall rates.
- Thorough Evaluation of Model Performance: Conducting a detailed analysis of learning curves, confusion matrices, and performance metrics to ensure the model's reliability and its capability to generalize.
- Generalization and Inference on Test Data: Verifying the model's robustness through generalization tests using validation images, an unseen test image, and a test video, showcasing its real-world applicability and efficiency.
- Real-Time Traffic Analysis: Developing an algorithm to quantify traffic density by real-time vehicle counting and traffic intensity analysis on test video footage.
- Preparation for Cross-Platform Deployment: Exporting the optimized model in the ONNX format to ensure cross-platform compatibility and facilitate deployment across diverse environments.
The Top-View Vehicle Detection Image Dataset for YOLOv8 is essential for tasks like traffic monitoring and urban planning. It provides a unique perspective on vehicle behavior and traffic patterns from aerial views, facilitating the creation of AI models that can understand and analyze traffic flow comprehensively.
- π Class: 'Vehicle' including cars, trucks, and buses.
- πΌοΈ Total Images: 626
- π Image Dimensions: 640x640 pixels
- π Format: YOLOv8 annotation format
Each image is carefully pre-processed and standardized to ensure consistency and high-quality training data for our model.
The dataset is meticulously split into:
- Training Set: 536 images for model training with diverse scenarios.
- Validation Set: 90 images for unbiased model performance evaluation.
Augmentations, including horizontal flips, are applied to enhance the training set's robustness, ensuring the model learns to generalize well across varied traffic conditions.
This dataset is pivotal in developing sophisticated vehicle detection models and shaping intelligent transportation systems for smarter city infrastructures.
- The dataset is curated from Pexels, offering diverse top-view videos for a rich vehicle detection dataset.
- Images were extracted using Roboflow at a rate of 1 frame per second, ensuring a wide variety of vehicle types and scenarios.
The dataset is publicly available on Roboflow and Kaggle:
- Roboflow Project: Top-View Vehicle Detection
- Kaggle Dataset: Top-View Vehicle Detection Image Dataset
- images/: Directory containing cover images and sample images used in notebooks and demos.
- models/: Contains the fine-tuned YOLOv8 models in
.pt(PyTorch) and.onnxformats for compatibility. - LICENSE: Legal document describing usage rights and limitations of the project.
- README.md: Overview and essential project information.
- real_time_traffic_analysis.py: Main Python script running the complete complex traffic analysis including detection, motion filtering, speed estimation, and color classification.
- real_time_traffic_analysis_minorchanges.py: Python script variant with intermediate code changes and improvements over initial version.
- real_time_traffic_analysis_initial.py: Initial baseline code performing basic vehicle detection and lane counting.
- motion_utils.py: Helper Python file with functions for motion detection and filtering.
- sample_video.mp4: Sample input video file used for testing and demonstration.
- real-time_traffic_density_estimation_yolov8.ipynb: Jupyter notebook documenting the model training and evaluation pipeline.
- Running_Real-Time_Traffic_Analysis.gif: Animated GIF showing real-time analysis in action.
To experience the full capabilities of the YOLOv8 Traffic Density Estimation project on your local machine, follow these steps:
-
Clone the Repository: Start by cloning the project repository to your local system using the command below:
git clone https://github.com/Gauss243J/real-time-traffic-density.git
-
Navigate to the Project Directory: After cloning, change into the project directory with:
cd YOLOv8_Traffic_Density_Estimation
Get hands-on with the model development process and see the results of traffic density estimation:
- Download the Dataset: Access the dataset from Kaggle. Download and extract it to a known directory on your machine.
- Open the Notebook: Launch Jupyter Notebook or JupyterLab and open
real-time_traffic_density_estimation_yolov8.ipynbto explore the model development pipeline. - Install Dependencies: Ensure all necessary Python libraries are installed for flawless execution.
- Update Paths: Update the paths in the notebook for the dataset, sample image, and sample video to their respective locations on your local system.
- Run the Notebook: Execute all cells in the notebook to step through the data preprocessing, model training, and evaluation phases.
Witness the real-time traffic analysis capability of our YOLOv8 model:
- Install Ultralytics YOLO: Ensure you have the
ultralyticspackage installed by running:pip install ultralytics
- Run the Analysis Script: Execute the script to start the real-time traffic density estimation:
python real_time_traffic_analysis_initial.pypython real_time_traffic_analysis_minorchanges.pypython real_time_traffic_analysis.py- Real-Time Analysis: The video window will display the live traffic analysis. To exit, simply press 'q' while the video window is active.
This GIF showcases our algorithm running in real-time:
- π₯ Project Demo: Watch the live demonstration of this project on YouTube.
- π Kaggle Notebook: Interested in a Kaggle environment? Explore the notebook here.
- π Dataset Source: Available on both Roboflow and Kaggle.
- π€ Connect on LinkedIn: Have questions or looking for collaboration? Let's connect on LinkedIn.



