This project focuses on driver distraction activities detection via images, which is useful for vehicle accident precaution. We aim to build a high-accuracy classifiers to distinguish whether drivers is driving safely or experiencing a type of distraction activity.
- Pip Package : https://pypi.org/project/Distracted-Driver-Detection/
- WebSite : https://distracteddriver-detection-app.herokuapp.com/
- Android-app : [app-debug.zip](https://github.com/MohamedSebaie/Distracted-Driver-Detection-Project-TechnoColabs/files/8009103/app-debug.zip)
DDD2.mp4
DDD3.mp4
According to the CDC motor vehicle safety division, one in five car accidents is caused by a distracted driver. Sadly, this translates to 425,000 people injured and 3,000 people killed by distracted driving every year.
In this project, I have created and refined machine learning models to detect what the driver is doing in a car given driver images. This is done by predicting the likelihood of what the driver is doing in each picture.
Given a dataset of images, an algorithm needs to classify each driver's behaviour and determine if they are driving attentively, wearing their seatbelt, or taking a selfie with their friends in the backseat etc ? This can then be used to automatically detect drivers engaging in distracted behaviours from dashboard cameras.
Following are needed tasks for the development of the algorithm:
-
Download and preprocess the driver images
-
Build and train the model to classify the driver images
-
Test the model and improve the model using different techniques.
The provided data set has driver images, each taken in a car with a driver doing something in the car (texting, eating, talking on the phone, makeup, reaching behind, etc). This dataset is obtained from Kaggle(State Farm Distracted Driver Detection competition).
Following are the file descriptions and URL’s from which the data can be obtained :
- imgs.zip - zipped folder of all (train/test) images
- sample_submission.csv - a sample submission file in the correct format
- driver_imgs_list.csv - a list of training images, their subject (driver) id, and class id
The 10 classes to predict are:
-
c0: safe driving
-
c1: texting - right
-
c2: talking on the phone - right
-
c3: texting - left
-
c4: talking on the phone - left
-
c5: operating the radio
-
c6: drinking
-
c7: reaching behind
-
c8: hair and makeup
-
c9: talking to passenger
There are 102150 total images. Of these 17939 are training images,4485 are validation images and 79726 are training images. All the training, validation images belong to the 10 categories shown above. The images are coloured and have 640 x 480 pixels
- Initially the images are divided into training and validation sets.
- The images are resized to a square images i.e. 224 x 224 pixels.
- All three channels were used during training process as these are color images.
- The images are normalised by dividing every pixel in every image by 255.
- To ensure the mean is zero a value of 0.5 is subtracted.
- Install:
pip install Distracted-Driver-Detection
- Download the Finetunned Model Weights
import gdown
PytorchURL = 'https://drive.google.com/uc?id=1P9r7pCc-5eTmW4krT4GZ1F6w_miTtxJA'
TfLiteURL = 'https://drive.google.com/uc?id=1WbZD6PMETHIH6oMj0bzyG3BoDUlyO2Ll'
TestImagesURL = 'https://drive.google.com/uc?id=1sodvME9eXHuZ-4qjTxmxsLsfFsg99KpK'
PytorchModel = 'model_ft.pth'
TfLiteModel = 'model.tflite'
TestImages = 'test_imgsN.zip'
gdown.download(PytorchURL, PytorchModel, quiet=False)
gdown.download(TfLiteURL, TfLiteModel, quiet=False)
gdown.download(TestImagesURL, TestImages, quiet=False)
- Import the DistractedDriverDetection_Utils from distracted_driver_detection :
from distracted_driver_detection import DistractedDriverDetection_Utils
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
- Detect The Distraction Class for the Driver Using Pytorch Weights:
# Run the Below Function by Input your image Path to get the outPut class and probability for the driver distraction class then show it
class_,pro = DistractedDriverDetection_Utils.PredictClass(imgPath)
print(class_,pro)
plt.imshow(mpimg.imread(imgPath));
# Plot Batch of Test Images from directory with Detection
DistractedDriverDetection_Utils.predMulti_images(test_img_dir,nImages=4)
- Detect The Distraction Class for the Driver Using Tesorflow Lite Model:
# Run the Below Function by Input your image Path to get the outPut class and probability for the driver distraction class then show it
class_,pro = DistractedDriverDetection_Utils.tfliteModel_Prediction(imgPath)
print(class_,pro)
plt.imshow(mpimg.imread(imgPath));
# Plot Batch of Test Images from directory with Detection
DistractedDriverDetection_Utils.tfliteModel_Plot(test_img_dir,nImages=4)
- Abdullah Abdelhakeem
- Mohamed Sebaie
- Mahmoud Salama