DeepActionPotential commited on
Commit
8079da6
·
verified ·
1 Parent(s): c9280e3

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +115 -102
README.md CHANGED
@@ -1,102 +1,115 @@
1
- # Drowsy Detector
2
-
3
- ## About the Project
4
-
5
- Drowsy Detector is an end-to-end deep learning solution for detecting driver drowsiness from facial images. The project leverages transfer learning with a pre-trained ResNet50 model, custom data preprocessing, and a user-friendly Streamlit web interface for real-time predictions. It is designed to help improve road safety by providing an automated tool to identify signs of driver fatigue. The repository includes all code, a training and evaluation notebook, and demo media for easy testing and demonstration.
6
-
7
- ## About the Dataset
8
-
9
- This project is built upon the [Drowsiness Prediction Dataset](https://www.kaggle.com/datasets/rakibuleceruet/drowsiness-prediction-dataset) from Kaggle. The dataset contains thousands of labeled facial images of drivers, divided into two categories: "Fatigue Subjects" (drowsy) and "Active Subjects" (alert). Images are collected under various lighting conditions, backgrounds, and driver poses, making the dataset robust and suitable for real-world drowsiness detection. The dataset is organized into folders by class, and each image is labeled for supervised learning. This diversity and structure allow for effective training and evaluation of deep learning models for driver monitoring systems.
10
-
11
- ## Notebook Summary
12
-
13
- The notebook provides a comprehensive, step-by-step workflow for building a deep learning-based driver drowsiness detection system:
14
- - **Data Exploration:** Visualizes the dataset structure, displays sample images from each class, and analyzes class distribution to ensure balanced training.
15
- - **Data Preparation:** Implements a custom PyTorch dataset and DataLoader, applies image preprocessing (resizing, normalization), and uses data augmentation to improve model generalization.
16
- - **Model Architecture:** Utilizes transfer learning with a pre-trained ResNet50 model, adapting its final layers for binary classification and fine-tuning the last few layers.
17
- - **Training Loop:** Sets up the training process with early stopping to prevent overfitting, tracks loss and accuracy metrics, and saves the best-performing model.
18
- - **Evaluation:** Assesses model performance on validation and test sets, visualizes results with confusion matrices, and plots training/validation loss curves for diagnostics.
19
-
20
- ## Model Results
21
-
22
- ### Preprocessing
23
- - **Image Resizing:** All images are resized to 224x224 pixels to match ResNet50's input requirements.
24
- - **Normalization:** Images are converted to tensors and normalized to standardize input distributions.
25
- - **Augmentation:** The training set uses augmentations such as random flips and rotations to improve generalization and robustness.
26
-
27
- ### Training
28
- - **Transfer Learning:** The model uses a pre-trained ResNet50 backbone. All layers are frozen except the last three, which are fine-tuned on the drowsiness dataset.
29
- - **Custom Classifier Head:** The final fully connected layer is replaced with a sequence of linear, ReLU, and dropout layers, ending with a two-class output.
30
- - **Loss Function:** Cross-entropy loss is used for binary classification.
31
- - **Optimizer:** Adam optimizer is employed with a learning rate of 1e-4.
32
- - **Early Stopping:** Training is monitored on the validation set and stops early if validation loss does not improve for several epochs.
33
-
34
- ### Evaluation
35
- - **Accuracy:** The model achieves up to 96% accuracy on the test set, demonstrating strong performance in distinguishing between drowsy and alert drivers.
36
- - **Confusion Matrix:** The confusion matrix shows high true positive and true negative rates, with minimal misclassifications.
37
- - **Loss Curves:** Training and validation loss curves are plotted to visualize convergence and detect any signs of overfitting or underfitting.
38
-
39
- ## How to Install
40
-
41
- 1. **Clone the repository:**
42
- ```bash
43
- git clone <repo-url>
44
- cd DrowsyDetector
45
- ```
46
- 2. **Create and activate a virtual environment:**
47
- ```bash
48
- python -m venv venv
49
- # On Windows:
50
- venv\Scripts\activate
51
- # On macOS/Linux:
52
- source venv/bin/activate
53
- ```
54
- 3. **Install dependencies:**
55
- ```bash
56
- pip install -r requirements.txt
57
- ```
58
- This will install PyTorch, torchvision, Streamlit, Pillow, NumPy, and other dependencies.
59
-
60
- 4. **Download the dataset:**
61
- - Download the dataset from [Kaggle](https://www.kaggle.com/datasets/rakibuleceruet/drowsiness-prediction-dataset).
62
- - Extract it and place it in the appropriate directory as referenced in the notebook.
63
-
64
- ## How to Use the Software
65
-
66
- 1. **Demo Application:**
67
- - The project includes a Streamlit-based web application for real-time drowsiness detection.
68
- - To launch the demo, run:
69
- ```bash
70
- streamlit run app.py
71
- ```
72
- - The app allows you to upload an image of a driver and predicts whether the driver is drowsy or alert.
73
-
74
- 2. **Using Demo Media:**
75
- - Simply upload any image from the `assets` directory via the web interface and click predict button.
76
-
77
- ## [demo-video](assets/drowsy_demo.mp4)
78
-
79
- - **Demo Images:**
80
- ![demo1](assets/1.png)
81
- ![demo2](assets/2.png)
82
-
83
-
84
- 3. **Notebook Usage:**
85
- - Open the notebook in Jupyter or VS Code and run all cells to reproduce the training and evaluation process.
86
- - You can modify paths and parameters as needed to experiment with different settings.
87
-
88
- ## Technologies Used
89
-
90
- - **PyTorch:** The primary deep learning framework used for model definition, training, and inference. PyTorch provides flexibility for custom dataset handling and model customization.
91
- - **Torchvision:** Supplies pre-trained models (ResNet50), image transforms, and utility functions for computer vision tasks.
92
- - **Pandas & NumPy:** Used for data manipulation, analysis, and efficient numerical computations.
93
- - **Matplotlib:** For visualizing images, loss curves, and confusion matrices during exploration and evaluation.
94
- - **scikit-learn:** Provides metrics such as confusion matrix and accuracy score for model evaluation.
95
- - **Streamlit:** Enables rapid development of interactive web applications for model deployment and demonstration.
96
- - **Pillow:** Used for image loading and processing within the custom dataset class.
97
-
98
- These technologies together enable efficient data handling, model training, evaluation, and deployment in a user-friendly interface.
99
-
100
- ## License
101
-
102
- This project is licensed under the MIT License. You are free to use, modify, and distribute this software for personal or commercial purposes, provided that you include the original copyright and license.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: AI Text Detector
3
+ emoji: 🤖
4
+ colorFrom: indigo
5
+ colorTo: blue
6
+ sdk: streamlit
7
+ sdk_version: 1.30.0
8
+ app_file: app.py
9
+ pinned: false
10
+ license: mit
11
+ ---
12
+
13
+
14
+ # Drowsy Detector
15
+
16
+ ## About the Project
17
+
18
+ Drowsy Detector is an end-to-end deep learning solution for detecting driver drowsiness from facial images. The project leverages transfer learning with a pre-trained ResNet50 model, custom data preprocessing, and a user-friendly Streamlit web interface for real-time predictions. It is designed to help improve road safety by providing an automated tool to identify signs of driver fatigue. The repository includes all code, a training and evaluation notebook, and demo media for easy testing and demonstration.
19
+
20
+ ## About the Dataset
21
+
22
+ This project is built upon the [Drowsiness Prediction Dataset](https://www.kaggle.com/datasets/rakibuleceruet/drowsiness-prediction-dataset) from Kaggle. The dataset contains thousands of labeled facial images of drivers, divided into two categories: "Fatigue Subjects" (drowsy) and "Active Subjects" (alert). Images are collected under various lighting conditions, backgrounds, and driver poses, making the dataset robust and suitable for real-world drowsiness detection. The dataset is organized into folders by class, and each image is labeled for supervised learning. This diversity and structure allow for effective training and evaluation of deep learning models for driver monitoring systems.
23
+
24
+ ## Notebook Summary
25
+
26
+ The notebook provides a comprehensive, step-by-step workflow for building a deep learning-based driver drowsiness detection system:
27
+ - **Data Exploration:** Visualizes the dataset structure, displays sample images from each class, and analyzes class distribution to ensure balanced training.
28
+ - **Data Preparation:** Implements a custom PyTorch dataset and DataLoader, applies image preprocessing (resizing, normalization), and uses data augmentation to improve model generalization.
29
+ - **Model Architecture:** Utilizes transfer learning with a pre-trained ResNet50 model, adapting its final layers for binary classification and fine-tuning the last few layers.
30
+ - **Training Loop:** Sets up the training process with early stopping to prevent overfitting, tracks loss and accuracy metrics, and saves the best-performing model.
31
+ - **Evaluation:** Assesses model performance on validation and test sets, visualizes results with confusion matrices, and plots training/validation loss curves for diagnostics.
32
+
33
+ ## Model Results
34
+
35
+ ### Preprocessing
36
+ - **Image Resizing:** All images are resized to 224x224 pixels to match ResNet50's input requirements.
37
+ - **Normalization:** Images are converted to tensors and normalized to standardize input distributions.
38
+ - **Augmentation:** The training set uses augmentations such as random flips and rotations to improve generalization and robustness.
39
+
40
+ ### Training
41
+ - **Transfer Learning:** The model uses a pre-trained ResNet50 backbone. All layers are frozen except the last three, which are fine-tuned on the drowsiness dataset.
42
+ - **Custom Classifier Head:** The final fully connected layer is replaced with a sequence of linear, ReLU, and dropout layers, ending with a two-class output.
43
+ - **Loss Function:** Cross-entropy loss is used for binary classification.
44
+ - **Optimizer:** Adam optimizer is employed with a learning rate of 1e-4.
45
+ - **Early Stopping:** Training is monitored on the validation set and stops early if validation loss does not improve for several epochs.
46
+
47
+ ### Evaluation
48
+ - **Accuracy:** The model achieves up to 96% accuracy on the test set, demonstrating strong performance in distinguishing between drowsy and alert drivers.
49
+ - **Confusion Matrix:** The confusion matrix shows high true positive and true negative rates, with minimal misclassifications.
50
+ - **Loss Curves:** Training and validation loss curves are plotted to visualize convergence and detect any signs of overfitting or underfitting.
51
+
52
+ ## How to Install
53
+
54
+ 1. **Clone the repository:**
55
+ ```bash
56
+ git clone <repo-url>
57
+ cd DrowsyDetector
58
+ ```
59
+ 2. **Create and activate a virtual environment:**
60
+ ```bash
61
+ python -m venv venv
62
+ # On Windows:
63
+ venv\Scripts\activate
64
+ # On macOS/Linux:
65
+ source venv/bin/activate
66
+ ```
67
+ 3. **Install dependencies:**
68
+ ```bash
69
+ pip install -r requirements.txt
70
+ ```
71
+ This will install PyTorch, torchvision, Streamlit, Pillow, NumPy, and other dependencies.
72
+
73
+ 4. **Download the dataset:**
74
+ - Download the dataset from [Kaggle](https://www.kaggle.com/datasets/rakibuleceruet/drowsiness-prediction-dataset).
75
+ - Extract it and place it in the appropriate directory as referenced in the notebook.
76
+
77
+ ## How to Use the Software
78
+
79
+ 1. **Demo Application:**
80
+ - The project includes a Streamlit-based web application for real-time drowsiness detection.
81
+ - To launch the demo, run:
82
+ ```bash
83
+ streamlit run app.py
84
+ ```
85
+ - The app allows you to upload an image of a driver and predicts whether the driver is drowsy or alert.
86
+
87
+ 2. **Using Demo Media:**
88
+ - Simply upload any image from the `assets` directory via the web interface and click predict button.
89
+
90
+ ## [demo-video](assets/drowsy_demo.mp4)
91
+
92
+ - **Demo Images:**
93
+ ![demo1](assets/1.png)
94
+ ![demo2](assets/2.png)
95
+
96
+
97
+ 3. **Notebook Usage:**
98
+ - Open the notebook in Jupyter or VS Code and run all cells to reproduce the training and evaluation process.
99
+ - You can modify paths and parameters as needed to experiment with different settings.
100
+
101
+ ## Technologies Used
102
+
103
+ - **PyTorch:** The primary deep learning framework used for model definition, training, and inference. PyTorch provides flexibility for custom dataset handling and model customization.
104
+ - **Torchvision:** Supplies pre-trained models (ResNet50), image transforms, and utility functions for computer vision tasks.
105
+ - **Pandas & NumPy:** Used for data manipulation, analysis, and efficient numerical computations.
106
+ - **Matplotlib:** For visualizing images, loss curves, and confusion matrices during exploration and evaluation.
107
+ - **scikit-learn:** Provides metrics such as confusion matrix and accuracy score for model evaluation.
108
+ - **Streamlit:** Enables rapid development of interactive web applications for model deployment and demonstration.
109
+ - **Pillow:** Used for image loading and processing within the custom dataset class.
110
+
111
+ These technologies together enable efficient data handling, model training, evaluation, and deployment in a user-friendly interface.
112
+
113
+ ## License
114
+
115
+ This project is licensed under the MIT License. You are free to use, modify, and distribute this software for personal or commercial purposes, provided that you include the original copyright and license.