A real-time driver drowsiness detection system combining:
- Eye Aspect Ratio (EAR) via MediaPipe FaceMesh
- Fine-tuned MobileNetV2 CNN for eye-state classification
- Hybrid fusion logic (EAR + CNN) for robust detection
- Auto EAR calibration, blink detection, single-eye fallback
- Tkinter UI, session analytics, and auto-generated PDF reporting
Designed to perform reliably under eyeglasses, glare, occlusion, low light, and natural variations in eye shape.
Driver drowsiness is a major contributor to road accidents worldwide. This system focuses on early, reliable detection under real-world conditions to enable timely alerts and prevent fatigue-related crashes.
A pre-trained CNN model is already included:
models/eye_mobilenet_finetuned_v2.h5
Meaning you do NOT need to train anything to run the main system.
git clone https://github.com/gudisaketh/drowsy_hybrid.git
cd drowsy_hybridpython3 -m venv drowsy_env
source drowsy_env/bin/activate # macOS / Linux
drowsy_env\Scripts\activate # Windowspip install -r requirements.txtpython drowsiness_hybrid_ui_combo_auto.pyThis opens the Tkinter UI with:
- Live webcam feed
- EAR calculation
- CNN eye-state prediction
- Hybrid Awake / Blink / Drowsy decision
- Session logging & PDF generation
π’ This is the only script needed to run the system.
| File | Description |
|---|---|
| drowsiness_hybrid_ui_combo_auto.py | β Main Hybrid System (EAR + CNN + Auto Calibration + UI + Reports) |
| drowsiness_ear_ui_v2.1.py | EAR-only legacy version |
Users who want to train their own models can use:
| File | Description |
|---|---|
| train_mobilenet_eye_cnn_v2.py | Trains MobileNetV2 on open/closed eyes |
| finetune_mobilenet_eye_cnn_v2.py | Fine-tunes (unfreezes last 75 layers) |
| File | Description |
|---|---|
| evaluate_cnn_model.py | CNN accuracy, confusion matrix, ROC |
| evaluate_hybrid_system_template.py | Evaluate EAR+CNN hybrid with ground-truth labels |
| File | Description |
|---|---|
| models/eye_mobilenet_v2.h5 | Base MobileNet pretrained model |
| models/eye_mobilenet_finetuned_v2.h5 | β Final fine-tuned model used in the Hybrid system |
| Folder | Purpose |
|---|---|
| sample_dataset/ | Tiny open/closed dataset for reference |
| dataset_structure.md | Explains how to download/prepare MRL dataset |
| session_results/ | Auto-saved session statistics, logs, charts, PDFs |
| images/ | Architecture diagrams, training plots, UI previews |
- Keep the pre-trained model in
models/ - Install dependencies
- Run the main script:
python drowsiness_hybrid_ui_combo_auto.pyThat's it.
- Download the MRL Eye Dataset
- Follow folder structure in
dataset_structure.md - Train base model:
python train_mobilenet_eye_cnn_v2.py- Fine-tune:
python finetune_mobilenet_eye_cnn_v2.py- Replace the
.h5model inmodels/(optional) - Run UI normally:
python drowsiness_hybrid_ui_combo_auto.py- Export frames from video
- Create CSV with labels
- Update script paths
- Run:
python evaluate_hybrid_system_template.pyThis project uses the MRL Eye Dataset (476 MB):
π https://www.kaggle.com/datasets/tauilabdelilah/mrl-eye-dataset
Not included due to size.
A sample dataset is included to show proper structure.
More details β dataset_structure.md
- Input: 160Γ160 RGB eye crops
- Stage 1: Train top layers
- Stage 2: Unfreeze last 75 layers
- Output: open/closed
- Final performance: ~95β96% accuracy
Diagrams located in:
images/architecture/
Located in:
images/ui/UI.png
The UI displays:
- EAR
- CNN probability
- Hybrid decision
- Sliding window closed ratio
- EAR plot, histogram, pie chart
- Stats table & PDF export
- training_plot_v2.png
- finetune_plot_v2.png
- Glass glare may reduce CNN accuracy
- No yawn (MAR) detection
- No head-pose tracking
- Requires frontal face
- Webcam quality affects EAR precision
- Add yawn detection
- Add head pose estimation
- IR camera support
- Vision Transformer models
- Multi-sensor fusion
This project was designed and implemented end-to-end, including data pipelines, model training, real-time inference, UI integration, evaluation tooling, and session reporting.
MIT License β free to use, modify, distribute.
Saketh Gudi