Highway Vehicle Detection - Code & Models
A complete vehicle detection system for highway traffic monitoring. This repository contains the trained models, source code, and documentation - ready to use without requiring dataset downloads.
Quick Start
Installation
pip install ultralytics opencv-python numpy
Basic Usage
from ultralytics import YOLO
# Load the trained model
model = YOLO('models/yolov8m_stage2_improved_best.pt')
# Run inference on an image
results = model('path/to/image.jpg')
results[0].show()
# Process video
results = model('path/to/video.mp4', save=True)
Using the Main Application
python main.py
Repository Contents
Trained Models
models/yolov8m_stage2_improved_best.pt- Final model (recommended)models/yolov8m_stage1_smart_best.pt- Stage 1 model (for comparison)
Source Code
main.py- Complete vehicle detection and counting applicationexample_usage.py- Simple usage examplesrequirements.txt- Python dependenciestest_improved_model.bat- Windows testing script
Fine-tuning Dataset
finetune_dataset/images/- 92 fine-tuning imagesfinetune_dataset/labels/- Corresponding annotation filesfinetune_dataset/README.dataset.txt- Dataset informationfinetune_dataset/README.roboflow.txt- Roboflow export info
Configuration
dataset_configs/main_data.yaml- Main dataset configuration (8 classes)dataset_configs/finetune_data.yaml- Fine-tuning dataset configuration
Training Logs
training_logs/stage2_results.png- Training results visualizationtraining_logs/stage2_confusion_matrix.png- Confusion matrixtraining_logs/stage2_results.csv- Detailed training metricstraining_logs/stage2_val_batch0_pred.jpg- Sample validation predictions
Training Runs Structure
training_runs/stage1_smart/- Stage 1 training configuration and weightsargs.yaml- Training argumentsweights/last.pt- Last epoch weights
training_runs/stage2_improved/- Stage 2 training configuration and weightsargs.yaml- Training argumentsweights/last.pt- Last epoch weightsBoxF1_curve.png- F1 score curveBoxPR_curve.png- Precision-Recall curvelabels.jpg- Label distribution visualization
Documentation
PROJECT_REPORT.md- Complete project documentationREADME.md- This file
Model Performance
Classes Detected
- auto - Three-wheelers
- bus - Public transport vehicles
- car - Passenger cars
- lcv - Light Commercial Vehicles
- motorcycle - Two-wheelers
- multiaxle - Multi-axle heavy vehicles
- tractor - Agricultural/construction vehicles
- truck - Heavy vehicles
Training Stages
- Stage 1: Initial training on 8,219 highway images
- Stage 2: Fine-tuning on 92 additional images for improved truck/bus detection
Fine-tuning Dataset Details
- Images: 92 carefully selected highway images
- Focus: Improved detection of trucks and buses
- Classes: Enhanced examples for problematic vehicle types
- Format: YOLO format with bounding box annotations
- Quality: High-quality images with clear vehicle visibility
External Resources
Test Video
Watch the model in action on YouTube: Highway Vehicle Detection Demo
Main Dataset
Download the complete training dataset from Kaggle: Vehicle Detection 8 Classes Dataset
Technical Details
- Architecture: YOLOv8m (Medium)
- Framework: Ultralytics YOLO
- Input: Images/Videos
- Output: Bounding boxes with class labels and confidence scores
- Hardware: CPU/GPU compatible
Usage Examples
Vehicle Detection
from ultralytics import YOLO
import cv2
# Load the final model
model = YOLO('models/yolov8m_stage2_improved_best.pt')
# Detect vehicles in image
results = model('highway_image.jpg')
# Process results
for result in results:
boxes = result.boxes
for box in boxes:
x1, y1, x2, y2 = box.xyxy[0]
conf = box.conf[0]
cls = int(box.cls[0])
class_name = model.names[cls]
print(f"Detected: {class_name} (confidence: {conf:.2f})")
Video Processing with Counting
# Process video with vehicle counting
results = model('traffic_video.mp4', save=True, save_txt=True)
# The main.py script provides advanced counting and tracking features
Using the Complete Application
# Run the full application with counting and visualization
from main import VehicleCounter
counter = VehicleCounter()
counter.process_video('input_video.mp4', 'output_video.mp4')
Applications
- Highway traffic monitoring
- Vehicle counting and classification
- Traffic flow analysis
- Automated surveillance systems
- Road safety monitoring
- Traffic data collection
Related Repositories
- Full Dataset: highway-vehicle-detection-full - Complete project with datasets and videos
- Model Only: highway-vehicle-detection - Just the trained model
License
MIT License - Free to use for research and commercial purposes
Contributing
This is a research project. For questions or improvements, please contact the author.
Contact
Author: Nguyen Quoc Viet
Repository: https://huggingface.co/bichuche0705/highway-vehicle-detection-code
Citation
If you use this model in your research, please cite:
@misc{highway-vehicle-detection-code,
title={Highway Vehicle Detection - Code \& Models},
author={Nguyen Quoc Viet},
year={2024},
url={https://huggingface.co/bichuche0705/highway-vehicle-detection-code}
}
- Downloads last month
- 2,153