Skip to content

TITANBGG/Driver_Drownise_Detection_Program-

Repository files navigation

🧠 Driver Drowsiness Detection using YOLOv5 and LSTM

Real-time drowsiness detection system that uses YOLOv5 for face/eye detection and LSTM for fatigue classification based on temporal patterns. This AI-based solution aims to enhance driver safety by detecting early signs of drowsiness.


AdsΔ±z tasarΔ±m

πŸš€ Features

  • πŸŽ₯ Real-time webcam integration
  • πŸ‘οΈ Eye and face detection using YOLOv5
  • ⏱️ Temporal sequence modeling with LSTM
  • 🧠 Custom labeled dataset (awake/drowsy)
  • πŸ“Š Performance monitoring in Jupyter
  • πŸ”§ Modular design for easy training and customization

🧠 How It Works

  1. YOLOv5 model detects face and eyes from webcam feed.

  2. Eye regions are cropped and passed to a trained LSTM classifier.

  3. LSTM analyzes a sequence of frames to determine the state:

    • 🟒 Awake
    • πŸ”΄ Drowsy

part1

part2

The system reacts instantly and overlays the prediction label with bounding boxes on the live feed.


πŸ“ˆ Model Evaluation Results

πŸ”Ή Label Distribution Heatmap

Labels are well-distributed in terms of position and size. Balanced annotation increases detection accuracy.


πŸ”Ή Precision vs Confidence

Awake class achieves high precision at lower confidence thresholds, while drowsy class stabilizes later.


πŸ”Ή Precision-Recall Curve

  • Awake: 0.948
  • Drowsy: 0.861
  • mAP@0.5: 0.905

Indicates a reliable and balanced detection model.


πŸ”Ή Recall vs Confidence

High recall even at low confidence thresholds suggests effective detection capability.


πŸ”Ή Training Metrics

P_curve PR_curve R_curve

Loss values decrease steadily and performance metrics increase over epochs, showing good training convergence.


πŸ”Ή Training Batches

confusion_matrix results labels_correlogram labels F1_curve

Sample training images with labels. Variations in expression, angle, and lighting enhance model generalization.


πŸ”Ή Validation Results

train_batch0 train_batctrain_batch2 h1 val_batch0_labels val_batch0_pred

Predictions match the ground truth closely, validating model reliability.


πŸ“ Project Structure

driver_drownise_detection_Program/
β”œβ”€β”€ data/
β”œβ”€β”€ datasets/
β”œβ”€β”€ labelimg/
β”œβ”€β”€ yolov5/
β”œβ”€β”€ yolov5s.pt
β”œβ”€β”€ train_lstm.py
β”œβ”€β”€ main.py
β”œβ”€β”€ Drowsiness Detection Tutorial.ipynb
β”œβ”€β”€ requirements.txt
└── README.md

βš™οΈ Installation

git clone https://github.com/alinb/drowsiness-detection.git
cd drowsiness-detection
pip install -r requirements.txt

YOLOv5 repo must be cloned under yolov5/:

git clone https://github.com/ultralytics/yolov5.git

πŸ¦– Training

YOLOv5

cd yolov5
python train.py --img 640 --batch 16 --epochs 100 --data ../data/data.yaml --weights yolov5s.pt

LSTM

python train_lstm.py --data_dir datasets/ --epochs 50 --batch_size 32

πŸ“Ή Run Real-Time Detection

python main.py

πŸ“Š Final Thoughts

The project demonstrates that combining object detection with temporal sequence modeling (YOLO + LSTM) can effectively solve real-world problems such as driver fatigue monitoring. Future improvements could include:

  • Adding audio alerts
  • Deploying on mobile devices with TFLite
  • Expanding the dataset with night-time/low-light scenarios

πŸ“„ License

MIT Β© 2025 Ali Nebi Er


🀝 Acknowledgments

Built with support from OpenAI's GPT-4 and the YOLOv5 community.

About

Driver Drowsiness Detection using YOLOv5 and LSTM

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published