Driver Drowsiness Detection using CNN



Original Source Here

Description of the Problem Statement

The project aims at detecting drowsiness while driving to alert the driver at the right time to prevent any mishappening. The project uses a CNN model to predict whether a person feels drowsy or not based on whether the eyes are closed or open. The project’s main objective was to limit the number of trainable parameters of the CNN model to under 250K so that the system can be deployed on edge or computationally less efficient devices. The project has a direct application in the automobile industry, makes drive safer, and reduces the death toll caused by drowsy driving.

Building the CNN Model

The implementation uses a custom-designed Convolutional Neural Network that has the following characteristics —

  • Three Convolution Blocks having 2, 3, and 3 convolutional layers, respectively.
  • A BatchNormalization Layer follows each Convolution Layer.
  • A Dropout Layer follows each Convolution Block for avoiding overfitting and a MaxPool Layer.
  • 3 Fully Connected Layers follow convolution Layers for classification.

Defining the model using Keras —

Model: "sequential"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
conv1 (Conv2D) (None, 32, 32, 32) 896
_________________________________________________________________
batch_normalization (BatchNo (None, 32, 32, 32) 128
_________________________________________________________________
conv2 (Conv2D) (None, 32, 32, 32) 9248
_________________________________________________________________
batch_normalization_1 (Batch (None, 32, 32, 32) 128
_________________________________________________________________
dropout (Dropout) (None, 32, 32, 32) 0
_________________________________________________________________
max_pooling2d (MaxPooling2D) (None, 16, 16, 32) 0
_________________________________________________________________
conv3 (Conv2D) (None, 16, 16, 64) 18496
_________________________________________________________________
batch_normalization_2 (Batch (None, 16, 16, 64) 256
_________________________________________________________________
max_pooling2d_1 (MaxPooling2 (None, 8, 8, 64) 0
_________________________________________________________________
conv4 (Conv2D) (None, 8, 8, 64) 36928
_________________________________________________________________
batch_normalization_3 (Batch (None, 8, 8, 64) 256
_________________________________________________________________
dropout_1 (Dropout) (None, 8, 8, 64) 0
_________________________________________________________________
max_pooling2d_2 (MaxPooling2 (None, 4, 4, 64) 0
_________________________________________________________________
conv5 (Conv2D) (None, 4, 4, 64) 36928
_________________________________________________________________
batch_normalization_4 (Batch (None, 4, 4, 64) 256
_________________________________________________________________
conv6 (Conv2D) (None, 4, 4, 64) 36928
_________________________________________________________________
batch_normalization_5 (Batch (None, 4, 4, 64) 256
_________________________________________________________________
conv7 (Conv2D) (None, 4, 4, 64) 36928
_________________________________________________________________
batch_normalization_6 (Batch (None, 4, 4, 64) 256
_________________________________________________________________
dropout_2 (Dropout) (None, 4, 4, 64) 0
_________________________________________________________________
max_pooling2d_3 (MaxPooling2 (None, 2, 2, 64) 0
_________________________________________________________________
flatten (Flatten) (None, 256) 0
_________________________________________________________________
fc1 (Dense) (None, 128) 32896
_________________________________________________________________
dropout_3 (Dropout) (None, 128) 0
_________________________________________________________________
fc2 (Dense) (None, 128) 16512
_________________________________________________________________
dropout_4 (Dropout) (None, 128) 0
_________________________________________________________________
fc3 (Dense) (None, 2) 258
=================================================================
Total params: 227,554
Trainable params: 226,786
Non-trainable params: 768
_________________________________________________________________

The model was compiled with the Adam optimizer and a learning rate of 0.0001.

Drowsiness Detection Dataset

The project uses the Drowsiness_dataset present on the Kaggle platform. The dataset is present on this link. The original dataset contains four classes for classifying images into Open Eyes, Closed Eyes, Yawning, or No-Yawning. However, this project’s scope is to classify drowsiness based on whether the eyes are closed or open. So, I will be using only two classes of the dataset. Characteristics of the dataset are as follows —

  • The dataset contains a total of 1452 images in two categories.
  • Each category has 726 images.
  • The dataset is already balanced, so no need to balance the dataset.
  • Class Labels — ‘Open Eye’ and ‘Closed Eye’.
  • Class Labels were encoded such that 0 represents Open Eye and 1 illustrates Closed Eye.

Loading the dataset —

Preprocess the images to make the size of each image equal to (32, 32, 3). Then, the dataset is split into Train and Test Set in 80%-20% proportion.

Training the Model

Model training runs for a total of 200 epochs with a batch size of 128. ImageDataGenerator is used for randomizing the training images for better performance of the model.

Performance of the Model

The following Performance Metrics are used —

  • Loss vs Number of Epochs Plot
  • Accuracy vs Number of Epochs Plot
  • Classification Report
  • Confusion Matrix

The results of the metrics mentioned above are as follows —

AI/ML

Trending AI/ML Article Identified & Digested via Granola by Ramsey Elbasheer; a Machine-Driven RSS Bot

%d bloggers like this: