Traffic Violation Detection System
A deep learning-based system for detecting traffic rule violations using the Berkeley Deep Drive (BDD100K) dataset. This project aims to enhance Vehicle-to-everything (V2X) communication systems and integrate with the Violation Awareness and Control (VAC) system implemented in Bangalore.
Overview
This project leverages the BDD100K dataset and YOLO architecture to train models that can detect various traffic violations, designed to work with existing VAC infrastructure.
VAC System Integration
The Violation Awareness and Control (VAC) system in Bangalore is an intelligent traffic management solution with the following components:
Infrastructure Components:
- High-definition cameras at strategic intersections
- Edge processing units for real-time detection
- Central monitoring system
- Integration with e-challan generation system
- Automatic Number Plate Recognition (ANPR) system
Violation Detection Capabilities:
- Red light violations
- Stop line violations
- Wrong side driving
- Triple riding on two-wheelers
- Helmet violations
- Seat belt violations
- Phone usage while driving
- Lane discipline violations
System Workflow:
- Real-time video capture from traffic cameras
- AI-powered violation detection
- ANPR processing for vehicle identification
- Automated e-challan generation
- Digital evidence storage and management
- Violation notification dispatch
YOLO Architecture
Our system uses YOLOv8 (You Only Look Once) for object detection and violation recognition:
Model Architecture:
- Backbone: CSPDarknet
- Neck: PANet
- Head: Decoupled detection heads
- Input resolution: 640x640
Key Features:
- Single-stage detector for real-time processing
- Multi-scale feature fusion
- Spatial attention mechanisms
- Anchor-free detection
- Multiple loss functions for better convergence
Custom Modifications:
- Additional detection heads for violation-specific features
- Temporal analysis module for motion tracking
- Enhanced night-time detection capabilities
- Custom loss functions for violation detection
Berkeley Deep Drive Dataset (BDD100K)
The BDD100K dataset used in this project provides:
Dataset Specifications:
- 10K subset of the full dataset
- 100K video sequences
- 100M annotated frames
- 1100 hours of driving experience
- Diverse driving conditions (weather/time)
Annotations Include:
- Vehicle bounding boxes
- Traffic signals and signs
- Lane markings
- Road objects
- Weather conditions
- Time of day
Custom Annotations Added:
- Violation event markers
- Temporal violation sequences
- Traffic rule context
- Severity classifications
Traffic Violation Detection System
A deep learning-based system for detecting traffic rule violations using the Berkeley Deep Drive (BDD100K) dataset, specifically the 10K subset. This project aims to enhance Vehicle-to-everything (V2X) communication systems by automatically detecting and reporting traffic violations.
Overview
This project leverages the BDD100K dataset to train models that can detect various traffic violations such as:
- Running red lights
- Stop sign violations
- Illegal lane changes
- Speeding (contextual detection)
- Failure to yield
The trained models are designed to integrate with V2X systems, enabling real-time violation detection and reporting.
Project Structure
traffic-violation-detection/
βββ data/
β βββ bdd100k/ # BDD100K dataset
β β βββ images/ # Original images
β β βββ labels/ # Annotation files
β β βββ info/ # Dataset metadata
β βββ processed/ # Preprocessed data
βββ models/
β βββ checkpoints/ # Saved model checkpoints
β βββ configs/ # Model configuration files
βββ src/
β βββ data/
β β βββ preprocessing.py # Data preprocessing scripts
β β βββ loader.py # Data loading utilities
β βββ models/
β β βββ detector.py # Main detection model
β β βββ utils.py # Model utilities
β βββ training/
β β βββ trainer.py # Training loop implementation
β β βββ metrics.py # Evaluation metrics
β βββ visualization/
β βββ visualize.py # Visualization tools
βββ tests/ # Unit tests
βββ notebooks/ # Jupyter notebooks for analysis
βββ requirements.txt # Python dependencies
βββ README.md # This file
Installation and Setup
1. Environment Setup
First, ensure you have Python 3.8+ installed. Then create and activate a virtual environment:
# Create virtual environment
python -m venv venv
# Activate virtual environment
# On Windows:
venv\Scripts\activate
# On macOS/Linux:
source venv/bin/activate
2. Dependencies Installation
The project requires several dependencies categorized below. Install them using:
# Install all required packages
pip install -r requirements.txt
Core Dependencies (requirements.txt)
# Deep Learning Framework
torch>=2.0.0
torchvision>=0.15.0
timm>=0.9.0
transformers>=4.30.0
# Data Processing
numpy>=1.21.0
pandas>=1.5.0
pillow>=9.5.0
opencv-python>=4.7.0
albumentations>=1.3.0
scipy>=1.9.0
scikit-learn>=1.0.2
# Visualization and Logging
matplotlib>=3.7.0
seaborn>=0.12.0
tensorboard>=2.13.0
wandb>=0.15.0
# Development Tools
pytest>=7.3.1
black>=23.3.0
isort>=5.12.0
flake8>=6.0.0
mypy>=1.3.0
# CUDA Support (if using GPU)
cupy-cuda11x>=11.0.0 # Install appropriate version for your CUDA
Optional Development Dependencies (requirements-dev.txt)
# Documentation
sphinx>=6.0.0
sphinx-rtd-theme>=1.2.0
# Testing
pytest-cov>=4.0.0
pytest-mock>=3.10.0
# Profiling
memory-profiler>=0.60.0
line-profiler>=4.0.0
3. GPU Setup (Optional)
If using GPU acceleration:
- Install CUDA Toolkit (11.x recommended)
- Install cuDNN
- Verify GPU support:
import torch
print(torch.cuda.is_available())
print(torch.cuda.get_device_name(0))
4. Dataset Setup
- Download the BDD100K dataset (10K subset) from the official website
- Extract to
data/bdd100k/
- Run preprocessing:
python src/data/preprocessing.py --config configs/preprocess.yaml
Training
The model training process involves:
- Data preprocessing and augmentation
- Feature extraction using a backbone network
- Multi-head detection for different violation types
- Loss computation combining detection and classification losses
To train the model:
python src/training/trainer.py --config models/configs/default.yaml
Current Results
Our model achieves the following performance metrics on the BDD100K validation set:
- Mean Average Precision (mAP): 0.83
- Recall: 0.79
- F1-Score: 0.81
V2X Integration
The system is designed to integrate with V2X communication systems by:
- Providing real-time violation detection
- Generating standardized violation reports
- Supporting vehicle-to-infrastructure (V2I) communication
- Enabling secure data transmission
Future Development
Model Improvements
- Implement attention mechanisms for better context understanding
- Add temporal analysis for sequential frames
- Enhance night-time detection capabilities
System Integration
- Develop V2X communication protocols
- Create edge deployment optimizations
- Implement real-time processing pipeline
Additional Features
- Support for more violation types
- Weather condition adaptation
- Multi-camera fusion
- Integration with traffic management systems
Common Issues and Solutions
CUDA Out of Memory
- Reduce batch size in config file
- Enable gradient checkpointing
- Use mixed precision training
Dataset Loading
- Ensure correct folder structure
- Verify image paths in annotation files
- Check preprocessing pipeline
Training Pipeline
Data Preparation:
# Preprocess BDD dataset python src/data/preprocess_bdd.py --subset 10k # Generate violation annotations python src/data/generate_violations.py
Model Training:
# Train YOLO model python src/training/train_yolo.py --config configs/yolov8.yaml # Fine-tune for violations python src/training/finetune.py --weights checkpoints/pretrained.pt
Validation:
# Run validation python src/evaluation/validate.py --weights checkpoints/best.pt
VAC System Integration
Camera Setup:
# Configure camera streams python src/deployment/setup_cameras.py --config configs/cameras.yaml # Start violation detection python src/deployment/detect_violations.py --camera-ids all
E-Challan Integration:
# Start e-challan service python src/services/challan_service.py # Monitor violation queue python src/services/violation_queue.py
Performance Metrics
Detection Performance:
- [email protected]: 0.85
- [email protected]:0.95: 0.62
- FPS: 30 (on NVIDIA T4 GPU)
Violation Recognition:
- Red light violation accuracy: 92%
- Lane violation accuracy: 88%
- Speed violation accuracy: 85%
Future Development
Technical Improvements:
- Implement transformer-based detection head
- Add multi-camera tracking
- Enhance night-time performance
- Reduce false positives
System Integration:
- Deploy to edge devices
- Scale to multiple intersections
- Improve ANPR accuracy
- Real-time alert system
License
This project is licensed under the MIT License - see the LICENSE file for details. Acknowledgments
Aknowledgement
- berkeley Deep Drive (BDD) team for providing the dataset
- The open-source community
Model tree for virajitgp/dead-sec_confluence_2025
Base model
Ultralytics/YOLOv8