Skip to content

Latest commit

Β 

History

15 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Helmet Detection & Traffic Violation Detection System

πŸ“Œ Project Overview

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:

  • helmet
  • no_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

🎯 Project Objectives

The major objectives of this project are:

  1. Develop a Deep Learning-based helmet detection system.
  2. Train a lightweight YOLO11 classification model.
  3. Classify images into helmet and no-helmet categories.
  4. Evaluate the trained model using validation and test data.
  5. Save the best-performing trained model.
  6. Test the model on unseen images.
  7. Study the limitations of image classification for real-world traffic scenes.
  8. Establish a baseline for future rider-level traffic violation detection.
  9. Extend the system toward number plate detection and OCR in future phases.

🧠 Problem Statement

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.


πŸ’‘ Proposed Solution

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.


πŸ€– Model Used

YOLO11n Classification

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.


πŸ”„ Transfer Learning

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.


πŸ“‚ Dataset

The dataset is organized into three major subsets:

helmet_dataset/
β”‚
β”œβ”€β”€ train/
β”‚   β”œβ”€β”€ helmet/
β”‚   └── no helmet/
β”‚
β”œβ”€β”€ validation/
β”‚   β”œβ”€β”€ helmet/
β”‚   └── no helmet/
β”‚
└── test/
    β”œβ”€β”€ helmet/
    └── no helmet/

Classes

The project contains two classes:

0 β†’ helmet
1 β†’ no_helmet

The source dataset uses the categories:

helmet
no helmet

πŸ“Š Dataset Distribution

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.


🧹 Dataset Validation

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.


πŸ”¬ Exploratory Data Analysis

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.


βš™οΈ Training Configuration

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.


πŸ‹οΈ Training Process

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.


πŸ“‰ Loss and Optimization

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.


πŸ“ˆ Model Evaluation

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.


πŸ† Validation Results

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.


πŸ’Ύ Trained Model

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")

πŸ§ͺ Testing

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.


🌐 External Image Testing

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.


πŸŽ₯ Video Detection

Current Status

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.


⚠️ Why Classification Is Not Enough

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.


🚧 Current Limitations

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.


πŸ”¬ Research Direction

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

πŸš€ Future Improvements

1. Object Detection

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.


2. Rider-Level Helmet Detection

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.


3. Number Plate Detection

For riders classified as violating helmet rules, the system could detect the associated vehicle's number plate.

No Helmet
    ↓
Vehicle
    ↓
Number Plate

4. OCR

After detecting the number plate, OCR can be applied to extract the vehicle registration number.

Example:

Number Plate Image
        ↓
       OCR
        ↓
   DL01AB1234

5. Video Processing

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.


6. Real-Time 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.


πŸ“ Project Structure

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

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

πŸ› οΈ Technologies

The project uses:

Python
PyTorch
Ultralytics YOLO
YOLO11
OpenCV
NumPy
Pandas
Matplotlib
Jupyter Notebook

πŸ’» Hardware Environment

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.


πŸ“¦ Installation

Clone the repository:

git clone <YOUR-GITHUB-REPOSITORY-URL>
cd <PROJECT-FOLDER>

Create a virtual environment:

python -m venv venv

Activate it on Windows:

venv\Scripts\activate

Install dependencies:

pip install ultralytics
pip install torch torchvision
pip install opencv-python
pip install numpy pandas matplotlib
pip install jupyter

▢️ Running the Project

Training

Open:

training.ipynb

Run the notebook cells sequentially.

The trained model will be generated after training.


Testing

Open:

testing.ipynb

Load:

saved_models/helmet_model.pt

Alternatively:

python test.py

πŸ”„ Complete Current Workflow

                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

πŸ“š Research Significance

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.


πŸ” Responsible Use

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.


πŸ“Œ Current Project Status

Completed

  • 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

In Progress / Future

  • 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

πŸ“Š Final Result

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.


πŸ‘¨β€πŸ’» Author

Nishant Rajora

B.Tech Computer Science and Engineering Specialization: Data Science


πŸ“œ License

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.


⭐ Acknowledgement

This project uses the Ultralytics YOLO framework for Deep Learning-based computer vision.

Official documentation:

https://docs.ultralytics.com/

About

YOLO11n-based Deep Learning system for helmet and no-helmet image classification, designed as a foundation for automated traffic violation detection using Computer Vision.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages