Skip to content

garvit-010/Drowsiness_Detection_System

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🚗 Real-Time Driver Drowsiness Detection System

📌 Problem Statement

Driver fatigue and drowsiness are among the leading causes of road accidents, especially during night-time long-haul driving such as truck and highway transport. Traditional safety measures fail because they do not monitor the driver’s physical alertness in real time.

There is a strong need for a real-time, automated, and intelligent system that can:

  • Continuously monitor a driver
  • Detect whether the driver is awake or drowsy
  • Trigger alerts before an accident occurs
  • Be extendable to IoT-based safety systems

💡 Our Solution

This project implements a real-time drowsiness detection system using Deep Learning and Computer Vision. Working Video

Key Idea

  • Train a binary image classification model (Awake vs Drowsy)
  • Use a pretrained ResNet-18 for robust feature extraction
  • Perform live face detection via webcam
  • Predict driver state in real time
  • Raise alerts if drowsiness persists

Why this works

  • CNNs capture facial fatigue patterns
  • Transfer learning improves accuracy with limited data
  • Temporal frame tracking reduces false positives

🧠 System Architecture

Pipeline Flow:

Webcam Frame
     ↓
Face Detection (OpenCV Haar Cascade)
     ↓
Face Cropping & Preprocessing
     ↓
ResNet-18 Classifier
     ↓
Awake / Drowsy Prediction
     ↓
Alert Trigger (if drowsy persists)

🛠️ Tech Stack

  • Language: Python
  • Deep Learning: PyTorch, Torchvision
  • Model: ResNet-18 (Transfer Learning)
  • Computer Vision: OpenCV
  • Image Processing: Pillow, NumPy
  • Dataset Handling: YOLO-style labels
  • Deployment Ready: IoT & Edge-compatible

📂 Project Structure

├── datapreprocessing.py        # Dataset loading & preprocessing
├── ResNetmodel.py              # Model training & saving
├── runmodel.py                 # Real-time webcam inference
├── requirements.txt            # Project dependencies
├── drowsiness_detection_model.pth  # Trained model (generated)
└── README.md

⚙️ How to Run the Project

1️⃣ Install Dependencies

pip install -r requirements.txt

2️⃣ Dataset Preparation

Ensure the dataset follows this structure:

images/
 ├── img1.jpg
 ├── img2.jpg

labels/
 ├── img1.txt
 ├── img2.txt

Label format (YOLO-style):

0 → Awake
1 → Drowsy

3️⃣ (Optional) Preprocess Data

python datapreprocessing.py

This step:

  • Splits dataset into train/test
  • Saves metadata and NumPy arrays (optional)

4️⃣ Train the Model

python ResNetmodel.py

This will:

  • Train ResNet-18 on your dataset
  • Save the trained model as:
drowsiness_detection_model.pth

5️⃣ Run Real-Time Detection

python runmodel.py

Controls:

  • Webcam opens automatically
  • Press q to exit

🚨 Output Behavior

  • Green Box: AWAKE
  • Red Box: DROWSY
  • Alert Trigger: If drowsiness continues for multiple frames, a DROWSINESS ALERT is displayed.

🌐 Real-World Applications

  • 🚛 Truck & Bus Driver Monitoring

  • 🚗 Night-time highway safety

  • 🏭 Industrial machine operator alertness

  • 🧠 Workplace fatigue monitoring

  • 🔌 IoT integration with:

    • Buzzers
    • Seat vibration
    • Smart dashboards
    • Fleet monitoring systems

🔮 Future Enhancements

  • Eye Aspect Ratio (EAR) + blink analysis
  • Temporal models (LSTM / sliding window)
  • Face detection upgrade (MTCNN / RetinaFace)
  • Edge deployment (Jetson / Raspberry Pi)
  • IoT alerts (GSM / MQTT / CAN bus)
  • Driver fatigue analytics dashboard

About

Real-Time Driver Drowsiness Detection System

Topics

Resources

License

Stars

Watchers

Forks

Languages