The Helmet Detection & Traffic Violation Detection System is a Deep Learning and Computer Vision project designed to identify whether a two-wheeler rider is wearing a helmet.
The current implementation focuses on developing and evaluating a YOLO11n image classification model that classifies input images into two categories:
helmetno_helmet
The project is developed as the initial Deep Learning component of a larger automated traffic violation detection system.
The long-term objective is to extend the system from simple helmet classification toward a complete traffic monitoring pipeline involving:
- Rider detection
- Helmet/no-helmet detection
- Vehicle identification
- Number plate detection
- Optical Character Recognition (OCR)
- Violation evidence generation
The major objectives of this project are:
- Develop a Deep Learning-based helmet detection system.
- Train a lightweight YOLO11 classification model.
- Classify images into helmet and no-helmet categories.
- Evaluate the trained model using validation and test data.
- Save the best-performing trained model.
- Test the model on unseen images.
- Study the limitations of image classification for real-world traffic scenes.
- Establish a baseline for future rider-level traffic violation detection.
- Extend the system toward number plate detection and OCR in future phases.
Two-wheeler riders are required to wear helmets for road safety. However, manually monitoring helmet compliance across large traffic areas is difficult.
Traditional monitoring depends heavily on:
- CCTV operators
- Manual inspection
- Traffic police
- Random checking
This creates limitations in terms of:
- scalability
- response time
- continuous monitoring
- human effort
Computer Vision and Deep Learning can help automate the identification of helmet violations.
The proposed system investigates the use of YOLO-based Deep Learning to automatically classify helmet compliance from images.
The current system follows this workflow:
Input Image
β
βΌ
Image Preprocessing
β
βΌ
YOLO11n Classification Model
β
βΌ
Feature Extraction
β
βΌ
Classification
β
βββββββββββββββββ
βΌ βΌ
HELMET NO HELMET
β β
βΌ βΌ
Confidence Confidence
Score Score
The current model performs image classification, meaning it predicts the class of the complete input image.
Ultralytics' classification models return the predicted class and confidence score rather than object bounding boxes.
The project uses:
YOLO11n Classification
Model file:
yolo11n-cls.pt
YOLO11 supports multiple computer vision tasks, including detection, segmentation, classification, pose estimation, and oriented bounding boxes. The -cls model variant is specifically intended for image classification.
The n represents the nano model variant, which is designed to provide a lightweight balance between computational requirements and model performance.
Instead of training the model completely from random initialization, the project starts from a pretrained YOLO11 classification model.
Pretrained YOLO11n
β
βΌ
Learned General Features
β
βΌ
Helmet Dataset
β
βΌ
Fine-Tuning
β
βΌ
Helmet Classification Model
This approach allows the model to reuse previously learned visual features and adapt them to the helmet/no-helmet classification problem.
The dataset is organized into three major subsets:
helmet_dataset/
β
βββ train/
β βββ helmet/
β βββ no helmet/
β
βββ validation/
β βββ helmet/
β βββ no helmet/
β
βββ test/
βββ helmet/
βββ no helmet/
The project contains two classes:
0 β helmet
1 β no_helmet
The source dataset uses the categories:
helmet
no helmet
The current dataset contains approximately:
| Dataset Split | Images |
|---|---|
| Training | 1199 |
| Validation | 200 |
| Testing | 200 |
| Total | ~1599 |
The training set is used to learn the model parameters.
The validation set is used during model development to monitor performance.
The test set is reserved for evaluating the trained model on unseen data.
Before training, the dataset is checked for:
- Valid image files
- Correct folder structure
- Correct class names
- Missing files
- Corrupted files
- Unsupported image formats
Some files in the dataset were identified as invalid/corrupt despite having .jpg extensions and were excluded from the usable dataset.
This preprocessing step is important because invalid image files can cause errors during model training.
The project includes dataset inspection and analysis before model training.
The analysis focuses on:
- Dataset structure
- Number of images
- Class distribution
- Training/validation/test split
- Image availability
- Invalid files
- Sample images
The purpose of EDA is to understand the dataset before training the Deep Learning model.
The current training configuration is:
Model : YOLO11n Classification
Task : Image Classification
Epochs : 30
Image Size : 640 Γ 640
Batch Size : 16
Device : NVIDIA GPU
Optimizer : AdamW
Workers : 4
The model is trained using the Ultralytics YOLO framework.
Ultralytics provides training, validation, prediction and export workflows through its Python API and command-line interface.
The training process can be represented as:
Dataset
β
βΌ
Data Loading
β
βΌ
Image Preprocessing
β
βΌ
YOLO11n Pretrained Model
β
βΌ
Forward Pass
β
βΌ
Prediction
β
βΌ
Loss Calculation
β
βΌ
Backpropagation
β
βΌ
Optimizer Update
β
βΌ
Validation
β
βΌ
Next Epoch
This process is repeated for the configured number of epochs.
During training, the model calculates a loss value that represents the difference between its predictions and the expected class.
The optimizer then updates the model's parameters to reduce this loss.
The project uses:
AdamW
as the optimizer.
The training loss decreased substantially during the training process, indicating that the model was learning the classification task.
The model is evaluated using classification metrics.
The major metrics used include:
- Top-1 Accuracy
- Top-5 Accuracy
- Confidence Score
For image classification, Ultralytics exposes metrics such as top1 and top5 during validation.
The trained model achieved:
Top-1 Accuracy : 100%
Top-5 Accuracy : 100%
These results were obtained during the project's validation/evaluation process.
However, high accuracy on a particular dataset should not automatically be interpreted as equivalent real-world performance.
Further testing on diverse traffic images and videos is required.
The best trained model is stored as:
saved_models/
βββ helmet_model.pt
This file contains the trained YOLO11 classification model.
The model can be loaded using:
from ultralytics import YOLO
model = YOLO("saved_models/helmet_model.pt")The testing workflow is implemented in:
testing.ipynb
and:
test.py
The model can be tested using new images that were not used during training.
Example:
from ultralytics import YOLO
model = YOLO("saved_models/helmet_model.pt")
results = model.predict("image.jpg")
for result in results:
top1 = result.probs.top1
confidence = result.probs.top1conf
class_name = result.names[top1]
print("Prediction:", class_name)
print("Confidence:", confidence)Ultralytics classification inference exposes the predicted class through result.probs.top1 and its confidence through result.probs.top1conf.
The project also includes testing on external images.
The basic workflow is:
Internet Image
β
βΌ
Download Image
β
βΌ
Convert to RGB
β
βΌ
YOLO11 Model
β
βΌ
Prediction
β
βΌ
Helmet / No Helmet
β
βΌ
Confidence
This provides an additional way to check how the trained model behaves on images outside the original dataset.
The project explores video-based helmet violation detection, but the current trained model is a classification model.
Therefore, the current model should not be considered a complete multi-rider traffic video detector.
For example:
Traffic Camera
β
βΌ
Multiple Riders
β
βΌ
YOLO11 Classification
β
βΌ
Whole-image Classification
The model does not independently locate every rider.
Suppose a traffic image contains:
Rider 1 β Helmet
Rider 2 β No Helmet
Rider 3 β Helmet
A classification model does not inherently produce:
Rider 1 β Helmet
Rider 2 β No Helmet
Rider 3 β Helmet
with individual bounding boxes.
Instead, it predicts a class for the input image.
Object detection is the appropriate task when the system needs to identify where individual objects are located in an image.
The current implementation does not yet provide:
- Individual rider detection
- Rider bounding boxes
- Multiple rider tracking
- Motorcycle detection
- Number plate detection
- Number plate OCR
- Vehicle identification
- Automatic challan generation
- Violation database
- Real-time traffic enforcement
Therefore, the current project should be described as:
YOLO11-based Helmet/No-Helmet Image Classification
rather than claiming that it is already a complete automated traffic enforcement system.
The project can be extended into a complete multi-stage traffic violation detection system.
A possible future architecture is:
Traffic Video
β
βΌ
Rider Detection
β
βΌ
Helmet Detection
β
ββββββββββ΄βββββββββ
βΌ βΌ
Helmet No Helmet
β
βΌ
Number Plate Detection
β
βΌ
Plate Crop
β
βΌ
OCR
β
βΌ
Vehicle Number
β
βΌ
Violation Record
Replace or extend the current classification model with a YOLO object-detection model.
Potential classes:
person
motorcycle
helmet
no_helmet
number_plate
This would allow the system to locate objects using bounding boxes.
Instead of classifying the entire image, detect individual riders.
Example:
Rider 1 β Helmet
Rider 2 β No Helmet
Rider 3 β Helmet
This would make the system much more suitable for traffic surveillance.
For riders classified as violating helmet rules, the system could detect the associated vehicle's number plate.
No Helmet
β
Vehicle
β
Number Plate
After detecting the number plate, OCR can be applied to extract the vehicle registration number.
Example:
Number Plate Image
β
OCR
β
DL01AB1234
The system can be extended to process:
- CCTV footage
- Traffic camera footage
- Uploaded videos
- Webcam streams
Ultralytics supports video and stream inputs for appropriate YOLO tasks, including object detection.
Future development can focus on optimizing the model for:
- GPU inference
- Edge devices
- Real-time CCTV
- Low-latency processing
- Lightweight deployment
YOLO11 is designed to support different deployment environments, including NVIDIA GPU and edge-device scenarios.
Helmet-Detection/
β
βββ helmet_dataset/
β β
β βββ train/
β β βββ helmet/
β β βββ no helmet/
β β
β βββ validation/
β β βββ helmet/
β β βββ no helmet/
β β
β βββ test/
β βββ helmet/
β βββ no helmet/
β
βββ runs/
β βββ training results
β
βββ saved_models/
β βββ helmet_model.pt
β
βββ .gitignore
β
βββ source.txt
β
βββ test.py
β
βββ testing.ipynb
β
βββ training.ipynb
β
βββ verify.py
β
βββ yolo11n-cls.pt
β
βββ yolo26n.pt
β
βββ README.md
| File | Description |
|---|---|
helmet_dataset/ |
Helmet/no-helmet dataset |
training.ipynb |
Complete model training notebook |
testing.ipynb |
Model testing and prediction notebook |
test.py |
Python testing script |
verify.py |
Dataset/model verification |
saved_models/helmet_model.pt |
Trained model |
runs/ |
Training outputs and experiment results |
yolo11n-cls.pt |
Pretrained YOLO11 classification model |
yolo26n.pt |
Additional YOLO model checkpoint |
source.txt |
Source/reference information |
.gitignore |
Git ignored files |
README.md |
Project documentation |
The project uses:
Python
PyTorch
Ultralytics YOLO
YOLO11
OpenCV
NumPy
Pandas
Matplotlib
Jupyter Notebook
The project was developed and trained using a CUDA-enabled NVIDIA GPU.
The training environment supports GPU acceleration through PyTorch and CUDA.
This allows the model training process to be significantly faster than CPU-only training.
Clone the repository:
git clone <YOUR-GITHUB-REPOSITORY-URL>
cd <PROJECT-FOLDER>Create a virtual environment:
python -m venv venvActivate it on Windows:
venv\Scripts\activateInstall dependencies:
pip install ultralytics
pip install torch torchvision
pip install opencv-python
pip install numpy pandas matplotlib
pip install jupyterOpen:
training.ipynb
Run the notebook cells sequentially.
The trained model will be generated after training.
Open:
testing.ipynb
Load:
saved_models/helmet_model.pt
Alternatively:
python test.py DATASET
β
βΌ
Dataset Verification
β
βΌ
Data Preprocessing
β
βΌ
EDA / Analysis
β
βΌ
Pretrained YOLO11n-cls
β
βΌ
Transfer Learning
β
βΌ
Training
β
βΌ
Validation
β
βΌ
best.pt
β
βΌ
saved_models/helmet_model.pt
β
βΌ
Testing
β
βΌ
External Image Testing
β
βΌ
Helmet / No Helmet Prediction
The project demonstrates how modern Deep Learning can be applied to an important road-safety problem.
The current implementation provides a foundation for investigating:
- Automated helmet compliance monitoring
- Computer Vision-based traffic surveillance
- Lightweight Deep Learning models
- Real-time inference
- Rider-level violation detection
- Number plate recognition
- Automated traffic violation systems
The project can subsequently move from classification toward object detection + OCR, creating a more complete traffic violation pipeline.
A real-world traffic enforcement system would need to consider:
- Privacy
- Data protection
- False positives
- False negatives
- Camera quality
- Lighting conditions
- Occlusion
- Multiple riders
- Model bias
- Human verification
- Legal requirements
Therefore, model predictions should be carefully validated before being used for real-world enforcement decisions.
- Dataset organization
- Dataset verification
- Data preprocessing
- Dataset analysis
- YOLO11n classification model selection
- Transfer learning
- Model training
- Model validation
- Best model saving
- Image testing
- External image testing
- Project documentation
- Two-wheeler/rider object detection
- Individual rider helmet detection
- Number plate detection
- OCR
- Rider tracking
- Video-based violation detection
- Violation evidence generation
- Real-time deployment
The current system successfully demonstrates helmet/no-helmet image classification using YOLO11n.
The trained model achieves high validation accuracy on the available dataset and can classify new images with a confidence score.
However, the current implementation is a foundation rather than a complete traffic enforcement system.
The next major research step is to move from:
IMAGE CLASSIFICATION
to:
OBJECT DETECTION
+
NUMBER PLATE DETECTION
+
OCR
+
VIDEO PROCESSING
This progression would transform the current helmet classification project into a more complete automated traffic violation detection system.
Nishant Rajora
B.Tech Computer Science and Engineering Specialization: Data Science
This project is intended primarily for educational and research purposes.
If this project is used or extended for commercial deployment, review the applicable licenses of the software, pretrained models, datasets, and other third-party components.
For YOLO11, refer to the current Ultralytics licensing and usage terms.
This project uses the Ultralytics YOLO framework for Deep Learning-based computer vision.
Official documentation: