Skip to content

Comparing driver drowsiness detection with CNN + MobileNetV2 vs YOLOv11 for real-time accuracy and efficiency πŸ§ πŸš—. Exploring both deep learning models to prevent fatigue-related accidents πŸ˜΄πŸ’‘.

License

Notifications You must be signed in to change notification settings

sergio11/safedrive_drowsiness_detection

Repository files navigation

πŸš— Deep Learning for Safer Roads πŸš— Exploring CNN-Based and YOLOv11 Driver Drowsiness Detection πŸ’€

As part of my journey through a Deep Learning course, I developed this project to explore how artificial intelligence can contribute to making our roads safer. I focused on the challenge of driver drowsiness detection, a crucial issue given how many accidents are caused by fatigue every year. πŸ’₯🚘 The idea of using deep learning to potentially save lives made this an incredibly motivating and meaningful project to work on. ❀️‍πŸ”₯

Throughout the process, I experimented with two powerful approaches: a CNN-based model with Transfer Learning for image classification πŸ§ πŸ–ΌοΈ, and YOLOv8, a real-time object detection model integrated through Roboflow βš™οΈπŸŽ―. This allowed me to explore both accuracy-focused models and those designed for real-time inference, gaining a clearer understanding of their strengths, limitations, and real-world applications. β±οΈπŸ”

Working on this project helped me strengthen my grasp of key deep learning concepts, from feature extraction and model fine-tuning to evaluating metrics like precision, recall, and F1-score. πŸ“Š I also encountered important practical lessonsβ€”like how to handle imbalanced data, optimize for performance, and think critically about what it means to deploy AI in real-life, safety-critical situations. πŸ§ͺ⚠️

I extend my gratitude to the creators of the Driver Drowsiness Dataset (DDD) for providing a high-quality dataset that has been instrumental in training and evaluating our deep learning model for driver drowsiness detection.

The dataset, derived from the Real-Life Drowsiness Dataset, offers a diverse collection of over 41,790 labeled images, carefully preprocessed to focus on the driver’s facial region. The effort in extracting, annotating, and sharing this dataset greatly contributes to research and development in road safety and accident prevention through deep learning techniques.

For more details and citation, please refer to the original dataset:
Driver Drowsiness Dataset (DDD) on Kaggle

A special thank you to Esraa Meslam Sayed for the invaluable inspiration provided through his project, Driver Drowsiness Detection🚘😴(CNN ||MobileNetV2). His work laid the foundation for the development of this model and greatly influenced the approach taken in this project. The insights and techniques explored in his work served as a key resource, helping to guide the creation of an effective and robust diabetes prediction model. We truly appreciate the effort and dedication put into his research and contributions to the data science community

πŸ™ I would like to extend my heartfelt gratitude to Santiago HernΓ‘ndez, an expert in Cybersecurity and Artificial Intelligence. His incredible course on Deep Learning, available at Udemy, was instrumental in shaping the development of this project. The insights and techniques learned from his course were crucial in crafting the neural network architecture used in this classifier.

⚠️ Disclaimer

This project, Deep Learning for Safer Roads, is an educational and experimental exploration of deep learning models for detecting driver drowsiness. The primary goal of this work is to investigate the effectiveness of CNN-based models with Transfer Learning and YOLOv8 for real-time driver monitoring and fatigue detection.

The models and methods explored in this notebook are intended for learning and research purposes only

This repository is open for educational purposes and encourages further experimentation and development.

🌟 Explore My Other Cutting-Edge AI Projects! 🌟

If you found this project intriguing, I invite you to check out my other AI and machine learning initiatives, where I tackle real-world challenges across various domains:

πŸš™ Why is This Important? πŸš™

Driver fatigue is a major cause of road accidents worldwide 😴. Detecting drowsy driving in real-time is crucial for preventing accidents and ensuring road safety. This project leverages the Driver Drowsiness Dataset (DDD), a collection of images of drivers in Drowsy and Non-Drowsy states, to build two different models aimed at real-time detection of drowsiness. 🌍

πŸ’» Approaches Explored πŸ’»

1. CNN-based Models: The Power of Convolutional Neural Networks πŸ”

CNNs are at the heart of modern image recognition and excel at learning spatial hierarchies of image data. For this task, we use MobileNetV2, a lightweight and efficient CNN architecture that’s ideal for real-time applications in vehicles. πŸš—

  • Why CNNs?
    βœ… Efficient at detecting drowsiness through facial state recognition.
    βœ… Works great on smaller datasets.
    βœ… Uses pre-trained models to speed up the process. 🏎️

2. YOLOv8 with Roboflow: Real-Time Object Detection at Its Best πŸ•΅οΈβ€β™‚οΈ

YOLOv8 is a state-of-the-art object detection model designed for speed and accuracy. Paired with Roboflow, YOLOv8 becomes even more powerful by streamlining the dataset preparation and deployment process. πŸš€

  • Why YOLOv8?
    βœ… Super fast, making it perfect for real-time applications. ⏱️
    βœ… Capable of localizing and detecting multiple objects in a single frame.
    βœ… Roboflow integration simplifies dataset annotation and augmentation. πŸ“

🧠 How Does the Model Work? 🧠

The Driver Drowsiness Dataset (DDD) is the foundation for training both models. Here’s what you need to know about the data:

  • Image Format: RGB images with facial features of drivers.
  • Classes: Drowsy vs. Non-Drowsy.
  • Resolution: 227 x 227 pixels, optimized for deep learning tasks.
  • Size: 41,790+ labeled images.
  • File Size: ~2.32 GB of drowsiness-related data!

πŸ”₯ Project Goals πŸ”₯

  1. Evaluate the two modelsβ€”CNN-based transfer learning and YOLOv8 with Roboflowβ€”for detecting drowsy drivers.
  2. Compare their performance using metrics like accuracy, precision, recall, and F1-score.
  3. Optimize the models for real-time deployment in vehicles.

πŸ› οΈ Methodology πŸ› οΈ

We break the project into several stages:

1. Data Preprocessing 🧹

  • Normalize pixel values.
  • Augment data to improve generalization.
  • Split the dataset into training, validation, and testing sets.

2. Model Development πŸ’‘

  • Train CNN models with MobileNetV2 for transfer learning.
  • Train YOLOv8 using Roboflow for real-time object detection.

3. Model Evaluation πŸ“Š

  • Compare performance using key metrics.
  • Assess real-time feasibility for vehicle deployment.

4. Real-Time Testing ⏱️

  • Simulate real-world conditions and evaluate model responsiveness.

πŸ›£οΈ Why Does This Matter? πŸ›£οΈ

This project aims to reduce road accidents by detecting driver fatigue using AI. Through deep learning, we can proactively detect when a driver is drowsy, preventing potential accidents before they happen. Safer roads lead to lives saved. 🌟

πŸ€– Comparing the Two Approaches: CNN + Transfer Learning vs YOLOv8 with Roboflow βš–οΈ

1. CNN + Transfer Learning: Fast and Effective 🌟

This approach uses pre-trained CNNs (e.g., MobileNetV2) to classify driver states as drowsy or non-drowsy based on facial images.

  • Pros:

    • Quick setup.
    • Works well with smaller datasets.
    • Pre-trained models speed up training.
  • Cons:

    • No object localization.
    • Limited real-time suitability due to preprocessing.
    • May struggle with high-resolution data.

2. YOLOv8 + Roboflow: Real-Time Detection πŸš€

YOLOv8 excels at detecting and localizing objects (e.g., faces, eyes) in real-time, especially when paired with Roboflow.

  • Pros:

    • Perfect for real-time detection.
    • Detects and localizes multiple objects at once.
    • Simplified data preparation via Roboflow.
  • Cons:

    • Resource-heavy, requiring powerful hardware.
    • Higher complexity in setup and fine-tuning.
    • Time-intensive annotations for accurate detection.

Side-by-Side Comparison

Aspect CNN + Transfer Learning YOLOv8 + Roboflow
Primary Goal Classification (Drowsy vs. Non-Drowsy) Real-Time Detection and Localization
Real-Time Suitability Limited (Preprocessing adds latency) Optimized for real-time applications
Ease of Use Beginner-friendly, quick setup More complex, streamlined with Roboflow
Dataset Needs Small to moderate datasets Detailed annotations, larger datasets
Performance Focus Classification Accuracy Speed + Detection Accuracy
Hardware Requirements Moderate (CPUs or mid-tier GPUs) High (Powerful GPUs recommended)

πŸ“± Choosing the Best Approach for Mobile Integration πŸ€–

When integrating the drowsiness detection model into a mobile application, we need to consider specific factors such as real-time performance, model size, and resource limitations. Let's explore the strengths of each approach and decide which one fits best for mobile deployment with TensorFlow Lite or YOLOv8.

1. CNN + Transfer Learning (MobileNetV2): Lightweight and Efficient πŸš€

If you're building a mobile app where speed and efficiency are critical, CNN-based models like MobileNetV2 are a great option.

  • Why use CNN + Transfer Learning for Mobile?

    • 🏎️ Lightweight and fast: MobileNetV2 is designed for resource-constrained environments, making it perfect for real-time mobile applications.
    • πŸ“‰ Smaller model size: Using TensorFlow Lite, the model can be deployed as a compact version to the mobile device.
    • ⚑ Real-time performance: MobileNetV2 ensures real-time drowsiness detection even on devices with lower processing power.
  • When should you use it?

    • You have limited hardware resources (e.g., mobile devices with moderate performance).
    • You need a lightweight and fast model that works efficiently with TensorFlow Lite.
    • You don’t need object localization or detecting multiple features within the image.

2. YOLOv8 with Roboflow: Real-Time Detection with Robust Features πŸ”₯

YOLOv8 excels in object detection and is ideal if your mobile app requires real-time detection and localization of features like faces or eyes.

  • Why use YOLOv8 for Mobile?

    • ⚑ High-speed detection: YOLOv8 is optimized for real-time processing, making it perfect for mobile apps that need fast response times.
    • πŸ› οΈ Advanced localization: YOLOv8 can detect and localize facial features, offering more detailed insights into the driver’s state.
    • πŸ‹οΈβ€β™‚οΈ Better for powerful devices: If you’re targeting high-end devices with robust processing power, YOLOv8 will deliver optimal performance.
  • When should you use it?

    • Your mobile app needs to detect multiple objects or localize faces/eyes.
    • You have access to high-performance hardware on the device (e.g., high-end smartphones).
    • You need a complete detection and classification system in a single pipeline.

Which One to Choose for TensorFlow Lite or YOLO?

  • Go for CNN + Transfer Learning (MobileNetV2) if:

    • You need a lightweight model that runs efficiently on mobile devices with limited computational power.
    • You're aiming for real-time performance with a fast deployment using TensorFlow Lite.
  • Go for YOLOv11 with Roboflow if:

    • You need advanced object detection and localization (e.g., detecting faces or eyes).
    • Your app will run on high-performance mobile devices that can handle the increased computational load.
    • You want an end-to-end system that seamlessly combines real-time detection and classification.

Final Thoughts 🧠

Both models have their strengths, and the best choice will depend on the specific needs of your mobile app. If you're looking for a lightweight and efficient model for real-time performance, MobileNetV2 is the way to go. However, if your focus is on advanced detection and localization with high-end hardware, YOLOv8 will offer the performance you need for a powerful real-time solution. πŸš€

Screenshots

πŸš€ Let’s Dive In! πŸš€

Both models are powerful tools for driver drowsiness detection, and each offers unique benefits. The choice of approach depends on your specific goals, dataset, and available resources.

πŸ“š References

⚠️ Disclaimer

This project, Deep Learning for Safer Roads, is an educational and experimental exploration of deep learning models for detecting driver drowsiness. The primary goal of this work is to investigate the effectiveness of CNN-based models with Transfer Learning and YOLOv8 for real-time driver monitoring and fatigue detection.

The models and methods explored in this notebook are intended for learning and research purposes only

This repository is open for educational purposes and encourages further experimentation and development.

πŸ™ Acknowledgments

A huge thank you to Ismail Nasri for providing the dataset that made this project possible! 🌟 The dataset can be found on Kaggle. Your contribution is greatly appreciated! πŸ™Œ

A special thank you to Esraa Meslam Sayed for the invaluable inspiration provided through his project, Driver Drowsiness Detection🚘😴(CNN ||MobileNetV2). His work laid the foundation for the development of this model and greatly influenced the approach taken in this project. The insights and techniques explored in his work served as a key resource, helping to guide the creation of an effective and robust diabetes prediction model. We truly appreciate the effort and dedication put into his research and contributions to the data science community

πŸ™ I would like to extend my heartfelt gratitude to Santiago HernΓ‘ndez, an expert in Cybersecurity and Artificial Intelligence. His incredible course on Deep Learning, available at Udemy, was instrumental in shaping the development of this project. The insights and techniques learned from his course were crucial in crafting the neural network architecture used in this classifier

Contribution

Contributions to this project are highly encouraged! If you're interested in adding new features, resolving bugs, or enhancing the project's functionality, please feel free to submit pull requests.

Get in Touch πŸ“¬

this project is developed and maintained by Sergio SΓ‘nchez SΓ‘nchez (Dream Software). Special thanks to the open-source community and the contributors who have made this project possible. If you have any questions, feedback, or suggestions, feel free to reach out at dreamsoftware92@gmail.com.

Visitors Count

Please Share & Star the repository to keep me motivated.

License βš–οΈ

This project is licensed under the Apache License 2.0, a permissive open-source software license that allows developers to freely use, modify, and distribute the software. πŸš€ This includes both personal and commercial use, with some conditions for distribution and modification. πŸ“œ

Key terms of the Apache License 2.0:

  • You are allowed to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the software. πŸ’»
  • If you modify and distribute the software, you must include the original copyright notice, provide a copy of the Apache 2.0 license, and indicate any modifications made. πŸ“
  • You are not allowed to use the name of the project or its contributors to promote derived works without permission. βœ‹
  • The software is provided "as is," without any warranties, express or implied. πŸš«πŸ›‘οΈ

Please see the full license text below for more detailed terms.

Apache License Version 2.0, January 2005 http://www.apache.org/licenses/

Copyright (c) 2025 Dream software - Sergio SΓ‘nchez

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

About

Comparing driver drowsiness detection with CNN + MobileNetV2 vs YOLOv11 for real-time accuracy and efficiency πŸ§ πŸš—. Exploring both deep learning models to prevent fatigue-related accidents πŸ˜΄πŸ’‘.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published