Skip to content

gangeshbaskerr/DriverDrowsinessDetection-OneAPI

Repository files navigation

DRIVER_DROWSINESS_DETECTION_(CNN)-OneAPI made-with-jupyter-notebook migrated-to-oneapibuilt-by-team-geeksforthebadge GitHub last commit GitHub watchers


Inspiration

Accidents caused due to driver drowsiness are a major public health and safety issue, affecting millions of people every year. According to the National Safety Council, driving while drowsy is similar to driving while intoxicated, as it impairs drivers attention, reaction time, and decision making, leading to fatal or serious crashes. Several factors can increase the risk of drowsy driving, such as lack of sleep, sleep disorders, shift work, medications, and alcohol. Research shows that driver fatigue may be a contributory factor in up to 20% of road accidents, and up to one quarter of fatal and serious accidents. An estimated 1,550 deaths, 71,000 injuries, and $12.5 billion in monetary losses are due to drowsy drivers in a year.


Problem Statement

The number of accidents occuring has been increased a lot recently and one of the major reasons for it is drowsiness Therefore, there is a need for a better solution that can detect driver drowsiness accurately and unobtrusively, and provide timely feedback or intervention to prevent accidents.


Introduction

The drowsiness detection system monitors the driver's condition and issues an alert if it detects signs of drowsiness using CNN - Python, OpenCV. This system aims to reduce the number of accidents on the road by detecting the driver's drowsiness and warning them using an alarm⏰.


Approach

Here, we used Python, OpenCV, and Keras(Tensorflow) to build a system that can detect features from the face of the drivers and alert them if they ever fall asleep while driving. The system detects the eyes and prompts if it is closed or open. If the eyes are closed for 10 seconds, it will play the alarm to get the driver's attention to stop because the system has detected drowsiness. We have built a model of CNN network trained on a dataset using OneAPI that can detect closed and open eyes. Then OpenCV is used to get the live feed from the camera and run every frame through the CNN model to process it and classify whether it is opened or closed eyes.


Procedure

1️⃣ Pre-install all the required libraries

   1) OpenCV
   2) Keras
   3) Numpy
   4) Pandas
   5) OS

2️⃣ Understand the dataset

   The dataset which was used is a subset of the dataset from(https://www.kaggle.com/datasets/dheerajperumandla/drowsiness-dataset)
   it has 4 folder which are
   1) Closed_eyes - having 726 pictures
   2) Open_eyes - having 726 pictures
   3) Yawn - having 725 pictures
   4) no_yawn - having 723 pictures

3️⃣ Data preprocessing

  1. preprocess the images from the closed_eye, open_eye, yawn and no_yawn folder.

  2. Resizing all the images to the same dimensions and converting the images into numpy arrays.

  3. The dataset will be split into training, validation, and testing sets.

4️⃣ Build and train the CNN model

The CNN model is designed and trained to classify images as either the driver's eye is opened or closed.

5️⃣ Train the model using Intel OneAPI to get better results

How does OneApi provide better performance :

Today’s computer systems are heterogeneous and include CPUs, GPUs, FPGAs, and other accelerators. The different architectures exhibit varied characteristics that can be matched to specific workloads for the best performance. Having multiple types of compute architectures leads to different programming and optimization needs. oneAPI and SYCL provide a programming model, whether through direct programming or libraries, that can be utilized to develop software tailored to each of the architectures.

Advantages of using OneAPI :

  1. We can use Single code for both CPU and GPU (heterogeneous computing)
  2. To implement machine learning based IoT projects easily with less hardwares as the machine learning part happens in cloud
  3. To process files faster ie. it takes less time to run the epochs
  4. OneAPI allows users to transcend Hardware restrictions and provide better performance for low powered computers
  5. Accuracy will improve while using OneAPI

To migrate your project to OneAPI : click here! to get started

For reference : click here!

6️⃣ Save the model

   save the model to calculate the accuracy and loss

Accuracy and Loss

We did 80 epochs, to get a good accuracy from the model i.e. 98% for training accuracy and 97% for validation accuracy.


Output

Eyes opened 👀

Eyes closed


Learnings

  1. Building a CNN model using Intel oneDNN : OneAPI is an open-source software toolkit developed by Intel that simplifies the development of high-performance, heterogeneous applications. It allows developers to write code that can run efficiently on a variety of architectures, including CPUs, GPUs, and FPGAs. oneDNN (Deep Neural Network) is a part of oneAPI and is an optimized library for deep learning. It provides highly optimized building blocks for neural network models that run efficiently on a variety of hardware platforms.

  2. Machine Learning : How to use machine learning for identifiying the facial features from a drivers face to detect drowsiness.

  3. Convolutional Neural Network(CNN) : How to build, train and fine-tune convolutional neural networks for image and video classification.

  4. Preprocessinig the datasets : How to preprocess the data dowloaded from kaggle so that the machine learning could happen in a much better and efficient way.

  5. Different aspects of drowsiness during driving : I have studied the different causes and reasons for drowsiness to occur and how to resolve it.

  6. Facial regions and drowsiness: I have studied how the facial landmarks are identified using an ocular feature called eye aspect ratio and face landmarks.Eye regions are detected and extracted as regions of interest using a facial cue detector and The eye aspect ratio values are then calculated, analyzed and saved for each image.

  7. Team work : Collaborating and communicating effectively in a team to deliver a project.

  8. Understanding the need for a drowsiness detection system in vehicles These are just a few examples of the knowledge and skills that i likely gained while building this project. Overall, building a drowsiness detection model is a challenging and rewarding experience that requires a combination of technical expertise and knowledge on facial cue detection.


Project Deployment

We have built an app using Flutter. Flutter helps Build, test, and deploy beautiful mobile, web, desktop, and embedded apps from a single codebase. It is a cross-platform app development framework by Google which goes hand in hand with the model to help ensure the safety of the user and other commuters.

As soon as the model detects drowsiness, the model will send an API request call to the client app, which notifies the user to take some rest and shows the navigation option to the nearest resting places. If the user isn't drowsy, the app will give 10 seconds buffer time within which the user can confirm that he isn't sleepy by pressing the prompt on the screen. If the user is drowsy he will get a option for getting driving assistance from the nearby driving service providers. If the user has been detected drowsy more than three times within 10 minutes, a notification is sent to the highway patrol and the nearby drivers as a concern for the safety of other drivers and the drowsy driver.


One more thing

  1. Distraction detection :

    When no eyes is detected while face is detected, It can be called distraction and that can also be added to this model.

  2. Alcohol gas detection :

    The MQ3 alcohol gas sensor is a module used for detecting alcohol, CH4, benzene, gasoline, hexane, CO, and LPG. It has a sensitive material namedSnO2 for alcohol gas detection, This code can be easily pared with MQ3 sensor to extend its detection in drunken driving.

  3. This module can be integrated with the driving system in cars to slow them down and bring them to stop when drowsiness is detected, its even better with autonomous cars as they can take over the driver and park the car in a safe place and prompt the driver to rest for few hours and then continue their journey.


Conclusion

Through this project there will be 20-30% decrease in number of accidents occuring. If this project is used efficiently it may also lead to huge decrease in percentage of accidents .

To view this project on Intel DevMesh : click here!


About

A project to detect the drowsiness of the driver and to alert the driver using an alarm.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published