Skip to content

Repository files navigation

💤 WakeUp App – Real-Time Driver Drowsiness Detection

An eye-closure monitoring mobile application for preventing drowsy driving accidents,
built with Flutter + Firebase and powered by a lightweight YOLOv5n model.


🏆 Award: 1st Place, Google Korea ML Bootcamp (2024, Cohort 3)
Selected as the top project among final demo teams, based on technical depth, completeness, and impact
Hosted by Google Korea and NIPA, the bootcamp focused on building deployable AI systems for real-world applications.

🚨 Motivation

Drowsy driving is the leading cause of fatal highway accidents in South Korea,
with a death rate nearly twice as high as drunk driving (2.9 vs. 1.5 per 100 incidents).

Despite its danger, only 17% of surveyed drivers recognized it as a top-3 risk factor.

Sources:

  • Korea Road Traffic Authority Press Release (2016–2020), Road Safety Division
  • National Police Agency Traffic Statistics (2019–2023)
  • Korea Transportation Safety Authority: 2023 Traffic Safety Perception Survey
  • AAA Foundation (2023): Driver self-assessment simulation
🔹 40% of drivers have experienced drowsiness at the wheel
🔹 Only 17% of respondents consider it a top-3 risk factor
🔹 Existing systems are costly, embedded, or lack accessibility

WakeUp is a lightweight and free mobile solution to detect eye closures, issue warnings, and log drowsy behavior patterns.


Features

  • 👁️ Real-time detection of eye closure (≥ 1.2s) with flutter_vision
  • 🔔 Audio + visual "WAKE UP" alert system via audioplayers
  • 🧾 Logging of drowsiness events with timestamps to Cloud Firestore
  • 📍 Geo-based risk detection using stored accident hotspot data in Cloud Firestore
  • 🧠 (!Not Implemented)Gemini API integration: personalized advice based on user history
  • ☁️ Full Firebase integration (Auth, Firestore, Cloud Functions)

Tech Stack

Layer Stack
Framework Flutter SDK 3.24.1 / Dart SDK 3.5.1
Frontend Flutter Widgets, Camera (0.11.0+2)
Backend Firebase (Auth, Cloud Firestore, Cloud Functions)
ML Inference YOLOv5n (PyTorch → TFLite), flutter_vision (1.1.4)
Location Services geolocator (10.1.1), geoflutterfire2 (2.3.15)
Storage & Security Cloud Firestore, flutter_secure_storage (9.2.2)
Additional Features audioplayers (6.1.0), google_generative_ai (0.4.6)
DevOps GCP (limited due to account expiration)

📈 Model Selection & Evaluation

We initially experimented with EfficientDet-lite and OpenCV-based CNN pipelines but discarded them due to memory overhead and lack of TFLite compatibility on mobile. After several iterations, YOLOv5n proved to be the best balance between speed and accuracy for our real-time use case.

Over 140k eye images were filtered, cleaned, and augmented to curate a ~9,200 image dataset.
Initially, the model output confidence hovered around 40% due to noise in the eye images.
After comprehensive dataset cleaning and augmentation, all final models achieved over 96% precision and recall, with F1 scores exceeding 0.95, indicating highly reliable detection performance.


Dataset Preprocessing Impact

Early training with raw, unprocessed data (YOLOv8s v0.1 and v0.2) yielded superficially strong metrics — high confidence scores and clean-looking PR/confusion matrices. However, real-world test accuracy was unreliable and unstable, clearly indicating overfitting and poor generalization. (All data was found in public and open source)

To address this, we implemented a three-phase preprocessing pipeline:

  1. Phase 1: Removed low-quality or misleading samples

    • Cropped-eye-only images

    • Half-open eyes, blurry or low-resolution images

    • Overexposed or light-reflecting cases

      example

      Screenshot 2025-05-03 203303

  2. Phase 2: Filtered for label clarity and spatial consistency

    • Manually reviewed for background interference, eye occlusion

    • Removed photos with multiple faces or corrupted labeling

      example

      Screenshot 2025-05-03 203402

  3. Phase 3: Augmented for diversity and robustness

    • Applied brightness adjustment and horizontal flipping

    • Final dataset curated to ~9,200 clean and balanced samples

      example

      Screenshot 2025-05-03 203418

Version Precision Recall F1 Score mAP@50 mAP@50–95 Notes
YOLOv8s_v0.1 ~0.87 ~0.89 ~0.88 ~0.91 ~0.455 ❌ Duplicates, unfiltered data
YOLOv8s_v0.2 ~0.90 ~0.90 ~0.90 ~0.80 ~0.40 ❌ Poor background filtering

After this pipeline was applied, models trained on the new data — YOLOv8n, YOLOv5s, and YOLOv5n — showed:

  • Consistently higher real-world reliability
  • Stable learning curves with minimal overfitting
  • An average +6.8% mAP@50–95 improvement
  • Better performance even with smaller architectures

✳️ Key Insight: Preprocessing quality directly influenced real-world robustness. A smaller model with clean data (e.g., YOLOv5n) outperformed a larger model trained on noisy data (e.g., YOLOv8s).


✅ Final Model Comparison (V1)

Model Precision Recall F1 Score mAP@50 mAP@50–95
YOLOv5n 0.9676 0.9619 0.9647 0.9631 0.4822
YOLOv5s 0.9710 0.9651 0.9680 0.9632 0.4978
YOLOv8n 0.9672 0.9461 0.9565 0.9629 0.5126

Real-World Test Results

Despite YOLOv8n's excellent validation score, its real-world test accuracy was ~60%, indicating overfitting or lack of robustness.
YOLOv5n and YOLOv5s consistently delivered >99% accurate predictions in real-time conditions.

YOLOv5n was selected due to its compact size, fast inference, and high accuracy — ideal for mobile deployment.


📊 Metrics Explanation

  • Precision: Correctness of predicted positive class (eye-closed).
  • Recall: Coverage of actual positives identified.
  • F1 Score: Harmonic mean of precision and recall.
  • mAP@50: Detection accuracy at 0.5 IoU.
  • mAP@50–95: Stricter range (0.5–0.95 IoU), indicates generalization.

Visual Comparisons

🔹 Training Loss Curves

YOLOv5n YOLOv5s YOLOv8n YOLOv8s_v0.1 YOLOv8s_v0.2

🔹 Precision-Recall Curves

YOLOv5n YOLOv5s YOLOv8n YOLOv8s_v0.1 YOLOv8s_v0.2

🔹 Confusion Matrices

YOLOv5n YOLOv5s YOLOv8n YOLOv8s_v0.1 YOLOv8s_v0.2

🔹 F1 Score vs Confidence

YOLOv5n YOLOv5s YOLOv8n YOLOv8s_v0.1 YOLOv8s_v0.2

WANDB Logs


System Architecture

graph TD
    %% Core Inputs
    A[Camera Module<br>flutter_camera] -->|Video Frame| B[YOLOv5n Model<br>flutter_vision]
    C[Geolocation Service<br>geolocator] -->|Location Data| D[Risk Assessment<br>geoflutterfire2]
    
    %% Core Processing
    B -->|Eye State Detection| E{Eye Closed ≥ 1.2s?}
    
    %% Event Flows
    E -->|Yes| F[Alert System<br>audioplayers]
    F -->|Audio & Visual| G[User Interface<br>Flutter Widgets]
    E -->|No| H[Normal Monitoring]
    
    %% Data Storage
    E -->|All Events| I[Event Logger]
    I --> J[(Firebase<br>Cloud Firestore)]
    J -->|Risk Zone Data| D
    
    %% Risk Analysis
    D -->|High Risk Area| F
    
    %% User Configuration
    K[User Settings<br>flutter_secure_storage] --> G
    
    %% Gemini Integration
    J -->|User Data History| L[Gemini API<br>google_generative_ai]
    L -->|Personalized Advice| G

    %% External API Update
    M[Traffic Accident Public Data API] -->|Update Risk Zones| J
    J -->|Fetches Risk Zones| D

    %% User Authentication
    N[User Authentication<br>Firebase Auth] --> G
    N --> J

   
    
    classDef flutter fill:#54C5F8,stroke:#333,stroke-width:2px,color:white;
    classDef ml fill:#f9f,stroke:#333,stroke-width:2px;
    classDef firebase fill:#FFCA28,stroke:#333,stroke-width:2px;
    classDef geo fill:#4CAF50,stroke:#333,stroke-width:1px,color:white;
    classDef ui fill:#bbf,stroke:#333,stroke-width:1px;
    classDef ai fill:#34A853,stroke:#333,stroke-width:1px,color:white;
    classDef api fill:#FF5722,stroke:#333,stroke-width:1px,color:white;
    
    class A,G,K flutter;
    class B,E ml;
    class J,N firebase;
    class C,D geo;
    class F,H,I ui;
    class L ai;
    class M api;
Loading

App Preview

Home Screen Screen Components
Log Window Alert Triggered (after 1.2s of closing)
Alert.Triggered.mp4

little bug: s should be ms at the report of 'eye closed time'


⚠️ Known Issues & Future Improvements

Known Issues Future Improvements
  • ❌ iOS TFLite inference not supported through flutter_vision
  • ❌ Inaccurate detection with front camera (box misalignment)
  • ❌ Bounding box sometimes remains frozen on Flutter widget tree
  • ⚠️ Occasional false positives at image edges (needs bounding mask tuning)
  • 🚀 Enhance Gemini integration with more sophisticated user pattern analysis
  • 🚀 Add persistent per-user dashboard with drowsiness history visualization

👤 Contributors

Jaeman Lee (Team Lead, ML + System Integration, Fullstack Development, Data Preprocessing, Model Training)
Juho Son (Data Preprocessing, Model Training, Resource Research)
Bonghyeon Baek (Data Preprocessing, Model evaluation, Resource Research)

🔗 Related Resources

📘 Notion Project Page 🧾 Presentation PDF 🤗 Model Download 📁 Preprocessed Dataset

About

NIPA-Google ML 3기 1팀

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages