Drowsiness Detection

Computer Vision & Deep Learning Project

This project focuses on building a Drowsiness Detection System using deep learning and computer vision techniques. The system detects early signs of driver drowsiness by analyzing the state of the driver’s eyes in real-time, aiming to improve road safety by alerting drowsy drivers.

Problem Statement

Drowsiness is one of the leading causes of road accidents worldwide. Detecting and alerting a drowsy driver on time can prevent potential accidents. This system uses a Convolutional Neural Network (CNN) to classify eye states (open or closed) and uses facial landmarks for precise eye region detection.

Objectives

Solution Approach

  1. Preprocessing: Applied data augmentation techniques to enhance the model’s robustness using the ImageDataGenerator class. Techniques include rescaling, rotation, width shift, height shift, shearing, zooming, and horizontal flipping.
  2. Model Architecture: Designed a CNN-based model using Keras with three convolutional layers followed by max-pooling and dense layers. The model processes grayscale images of the driver’s eyes.
  3. Real-Time Eye Detection: Utilized the Dlib library’s facial landmarks to precisely locate the eyes in each video frame captured from the webcam.
  4. Prediction and Alert System: Used a binary classifier to predict if the driver’s eyes are open or closed. If both eyes are detected as closed, the system issues an alert sound.

Dataset

The project leverages the MRL Eye Dataset, which contains labeled images of eyes in different states (open or closed). The dataset was divided into training, validation, and testing sets.

Model Implementation

Data Augmentation

train_datagen = ImageDataGenerator(
    rescale=1./255,
    rotation_range=20,
    width_shift_range=0.2,
    height_shift_range=0.2,
    shear_range=0.2,
    zoom_range=0.2,
    horizontal_flip=True,
    fill_mode='nearest')

Augmentation improved the model’s generalizability, allowing it to handle different angles and lighting conditions.

Model Architecture

The CNN model was defined as follows:

Model Compilation and Training

The model was compiled using the Adam optimizer with a learning rate of 0.001. The loss function used was binary_crossentropy. Metrics such as accuracy, precision, and recall were tracked during training.

model.compile(optimizer=Adam(learning_rate=0.001), 
              loss='binary_crossentropy', 
              metrics=[tf.keras.metrics.BinaryAccuracy(name='accuracy'),
                       tf.keras.metrics.Precision(name='precision'),
                       tf.keras.metrics.Recall(name='recall')])

Evaluation Metrics

The model was evaluated on both training and testing datasets. The final evaluation yielded the following metrics:

Metric Training Set Testing Set
Accuracy 0.98 0.95
Precision 0.97 0.94
Recall 0.96 0.93
Loss 0.10 0.15

Real-Time Detection and Alerting

The system captures video input using a webcam, applies Dlib’s face detection and landmark identification, and extracts eye regions. These eye regions are preprocessed and fed into the trained CNN model for prediction. If both eyes are classified as closed, an auditory alert is triggered using the winsound module.

Results and Visualization

A comparative bar chart between training and testing metrics:

Training vs Testing Metrics

Key Features

Demo

Conclusion

The Drowsiness Detection System leverages deep learning and computer vision to identify drowsiness and alert drivers in real-time. This system can be integrated into vehicles to enhance road safety and prevent accidents caused by drowsiness.

For the complete code and further details, you can visit the GitHub repository.

Next Project

Leaf Species Classification

Get in Touch

Interested in collaborating or have any questions? Reach out to me through this form.