Skip to content

Commit 66531ca

Browse files
authored
Create readme.md
Added the readme File
1 parent 4df0a11 commit 66531ca

File tree

1 file changed

+169
-0
lines changed
  • models/ML_Models/ResNET+CNN (Tranfer Learning)

1 file changed

+169
-0
lines changed
Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
# Eye Drowsiness Detection using ResNet50
2+
3+
A deep learning project for detecting driver drowsiness by classifying eye states as "awake" or "sleepy" using transfer learning with ResNet50.
4+
5+
## 🎯 Project Overview
6+
7+
This project implements a binary classification model to detect drowsiness in drivers by analyzing eye images. The model achieves **98.5% validation accuracy** using a pre-trained ResNet50 backbone with custom classification layers.
8+
9+
### Key Features
10+
- **Transfer Learning**: Utilizes pre-trained ResNet50 from ImageNet
11+
- **Binary Classification**: Classifies eyes as "awake" or "sleepy"
12+
- **High Accuracy**: Achieves 98.5% validation accuracy
13+
- **GPU Optimized**: Configured for Google Colab with GPU acceleration
14+
- **Production Ready**: Saved model ready for deployment
15+
16+
## 📊 Model Performance
17+
18+
| Metric | Training | Validation |
19+
|--------|----------|------------|
20+
| **Accuracy** | 97.76% | 98.50% |
21+
| **Loss** | 0.0600 | 0.0415 |
22+
23+
## 🗂️ Dataset
24+
25+
The project uses the **MRL Eye Dataset** from Kaggle containing:
26+
- **Training Set**: 50,937 images (80/20 split for train/validation)
27+
- **Validation Set**: 16,980 images
28+
- **Classes**: 2 (awake, sleepy)
29+
- **Image Size**: 224×224 pixels
30+
31+
**Dataset Source**: [MRL Eye Dataset on Kaggle](https://www.kaggle.com/datasets/akashshingha850/mrl-eye-dataset)
32+
33+
## 🏗️ Model Architecture
34+
35+
```
36+
ResNet50 (Pre-trained, Frozen)
37+
38+
GlobalAveragePooling2D
39+
40+
Dense(128, activation='relu')
41+
42+
Dropout(0.3)
43+
44+
Dense(2, activation='softmax')
45+
```
46+
47+
### Model Specifications
48+
- **Base Model**: ResNet50 (ImageNet pre-trained, frozen)
49+
- **Input Shape**: (224, 224, 3)
50+
- **Output**: 2 classes (awake/sleepy)
51+
- **Total Parameters**: ~25M (only ~260K trainable)
52+
- **Optimizer**: Adam
53+
- **Loss Function**: Binary Cross-Entropy
54+
55+
## 🚀 Getting Started
56+
57+
### Prerequisites
58+
- Python 3.7+
59+
- TensorFlow 2.x
60+
- Google Colab (recommended) or local GPU environment
61+
- Kaggle API credentials
62+
63+
### Installation & Setup
64+
65+
1. **Clone the repository**:
66+
```bash
67+
git clone https://github.com/yourusername/eye-drowsiness-detection.git
68+
cd eye-drowsiness-detection
69+
```
70+
71+
2. **Install dependencies**:
72+
```bash
73+
pip install tensorflow matplotlib kagglehub
74+
```
75+
76+
3. **Run in Google Colab**:
77+
- Upload `Drowsiness.ipynb` to Google Colab
78+
- Enable GPU: Runtime → Change runtime type → Hardware accelerator → GPU
79+
- Run all cells
80+
81+
### Usage
82+
83+
1. **Download Dataset**:
84+
```python
85+
import kagglehub
86+
path = kagglehub.dataset_download("akashshingha850/mrl-eye-dataset")
87+
```
88+
89+
2. **Train the Model**:
90+
```python
91+
# Configure paths
92+
train_folder_path = '/path/to/train'
93+
val_folder_path = '/path/to/val'
94+
95+
# Train model (5 epochs)
96+
history = model.fit(train_ds, validation_data=val_ds, epochs=5)
97+
```
98+
99+
3. **Save the Model**:
100+
```python
101+
model.save('/content/saved_model/resnet.keras')
102+
```
103+
104+
4. **Load and Use for Prediction**:
105+
```python
106+
import tensorflow as tf
107+
loaded_model = tf.keras.models.load_model('/path/to/resnet.keras')
108+
prediction = loaded_model.predict(new_image)
109+
```
110+
## 🔬 Training Details
111+
112+
### Hyperparameters
113+
- **Image Size**: 224×224 pixels
114+
- **Batch Size**: 16
115+
- **Epochs**: 5
116+
- **Learning Rate**: Adam default (0.001)
117+
- **Validation Split**: 20%
118+
- **Data Augmentation**: None (can be added for improvement)
119+
120+
### Training Results
121+
```
122+
Epoch 1/5: val_accuracy: 0.9753
123+
Epoch 2/5: val_accuracy: 0.9756
124+
Epoch 3/5: val_accuracy: 0.9761
125+
Epoch 4/5: val_accuracy: 0.9806
126+
Epoch 5/5: val_accuracy: 0.9850
127+
```
128+
## 🔧 Customization & Improvements
129+
130+
### Potential Enhancements
131+
- **Data Augmentation**: Add rotation, brightness, contrast adjustments
132+
- **Fine-tuning**: Unfreeze top layers of ResNet50 for better accuracy
133+
- **Real-time Processing**: Optimize for webcam/camera input
134+
- **Multi-class**: Extend to detect different levels of drowsiness
135+
- **Ensemble Methods**: Combine multiple models for better performance
136+
137+
### Fine-tuning Example
138+
```python
139+
# Unfreeze top layers for fine-tuning
140+
base_model.trainable = True
141+
for layer in base_model.layers[:-10]:
142+
layer.trainable = False
143+
144+
# Use lower learning rate
145+
model.compile(optimizer=tf.keras.optimizers.Adam(1e-5),
146+
loss='categorical_crossentropy',
147+
metrics=['accuracy'])
148+
```
149+
150+
## 📈 Performance Analysis
151+
152+
The model shows excellent performance with:
153+
- **No Overfitting**: Validation accuracy consistently higher than training
154+
- **Quick Convergence**: Reaches high accuracy within 5 epochs
155+
- **Stable Training**: Consistent improvement across epochs
156+
157+
## 🤝 Contributing
158+
159+
Contributions are welcome! Please feel free to:
160+
- Report bugs or issues
161+
- Suggest new features or improvements
162+
- Submit pull requests
163+
- Share your results and modifications
164+
165+
## 🙏 Acknowledgments
166+
167+
- **Dataset**: MRL Eye Dataset by akashshingha850 on Kaggle
168+
- **Base Model**: ResNet50 from TensorFlow/Keras
169+
- **Platform**: Google Colab for providing free GPU resources

0 commit comments

Comments
 (0)