AI-powered real-time driver safety monitoring system using advanced computer vision to detect and classify 12 types of distracted driving behaviors.
- Demo Video
- Application Screenshots
- Overview
- Live Demos
- Features
- Dataset
- Model Performance
- Architecture
- Installation
- Usage
- Deployment
- Repository Structure
- Technologies
- Contributing
- License
- Contact
- Acknowledgments
demo.mp4
Complete application walkthrough demonstrating real-time detection capabilities
SafeDrive AI is an advanced computer vision system designed to detect and prevent driver distractions in real-time. Using state-of-the-art YOLO object detection and deep learning classification models, the system identifies 12 different types of dangerous driving behaviors with high accuracy.
Phone Usage
- c1: Texting
- c2: Talking on the phone
Vehicle Controls
- c3: Operating the radio
- c0: Safe driving
Physical Activities
- c4: Drinking
- c5: Reaching behind
- c6: Hair and makeup
Social Interaction
- c7: Talking to passenger
Drowsiness Detection
- d0: Eyes closed
- d1: Yawning
- d2: Nodding off
- d3: Eyes open
Platform: Hugging Face Spaces
Technology: Gradio + ONNX Runtime
Link: https://huggingface.co/spaces/yeager07/distracted-driving-detection
Platform: Render.com
Technology: Flask + Docker + HF Spaces API
Link: https://driver-distraction-detection-and.onrender.com
- 12-class behavioral detection with 98.1% mAP@50
- Real-time processing for images and videos
- High accuracy with optimized inference speed
- Multiple model backends (ONNX Runtime)
- Gradio: Interactive drag-and-drop interface
- Flask: Modern responsive web application
- Analytics dashboards with detailed statistics
- Video processing with frame-by-frame analysis
- Docker containerization for consistent environments
- CI/CD pipeline via GitHub Actions
- Cloud hosting on Render.com and Hugging Face Spaces
- RESTful API for easy integration
| Split | Images | Percentage |
|---|---|---|
| Training | 17,909 | 80% |
| Validation | 2,238 | 10% |
| Testing | 2,240 | 10% |
| Total | 22,390 | 100% |
Source: Roboflow Universe - Distracted Driving Dataset v2
- High-quality annotations for all 12 behavior classes
- Diverse lighting conditions and camera angles
- Multiple driver demographics and vehicle types
- Rigorous train/validation/test split
- Publicly available for research
| Model | GFLOPs | Inference (ms) | mAP@50 | mAP@50-95 | Precision | Recall |
|---|---|---|---|---|---|---|
| YOLOv10N | 8.2 | 3.6 | 0.978 | 0.845 | 0.968 | 0.959 |
| YOLOv10S | 24.5 | 8.5 | 0.981 | 0.856 | 0.959 | 0.977 |
| YOLOv10M | 63.5 | 19.5 | 0.981 | 0.854 | 0.963 | 0.971 |
| YOLOv10L | 126.4 | 31.2 | 0.981 | 0.854 | 0.966 | 0.979 |
Selected Model: YOLOv10S (optimal balance of speed and accuracy)
| Model | Accuracy | AUC (OVR) | Inference/Batch (s) | Inference/Sample (s) |
|---|---|---|---|---|
| ConvNeXt-Tiny | 97.67% | 0.9988 | 0.0091 | 0.000285 |
| VGG19 | 96.98% | 0.9976 | 0.0028 | 0.000086 |
| ResNet50 | 95.88% | 0.9957 | 0.0107 | 0.000334 |
| EfficientNet-B0 | 95.88% | 0.9954 | 0.0133 | 0.000416 |
| MobileNetV2 | 95.47% | 0.9974 | 0.0082 | 0.000255 |
Key Insights:
- ConvNeXt-Tiny achieves highest accuracy and AUC
- VGG19 offers fastest inference time
- MobileNetV2 optimized for mobile deployment
┌─────────────────────────────────────────────────────────────┐
│ User Interface │
│ ┌──────────────┐ ┌──────────────┐ │
│ │ Gradio App │ │ Flask App │ │
│ │ (HF Spaces) │ │ (Render.com) │ │
│ └──────┬───────┘ └──────┬───────┘ │
└─────────┼──────────────────────────────┼──────────────────┘
│ │
▼ ▼
┌─────────────────────────────────────────────────────────────┐
│ Backend Services │
│ ┌─────────────────────┐ ┌─────────────────────┐ │
│ │ ONNX Runtime │ │ Gradio Client API │ │
│ │ (Local Inference) │ │ (HF Spaces) │ │
│ └─────────┬───────────┘ └─────────┬───────────┘ │
└────────────┼──────────────────────────────┼──────────────────┘
│ │
▼ ▼
┌─────────────────────────────────────────────────────────────┐
│ AI Models (ONNX) │
│ ┌─────────────────────────────────────────────────┐ │
│ │ YOLOv10n Detection Model (best.onnx) │ │
│ │ - 12 behavior classes │ │
│ │ - 640x640 input size │ │
│ │ - 98.1% mAP@50 accuracy │ │
│ └─────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────┘
┌─────────────┐
│ USER │
└──────┬──────┘
│ Upload Image/Video
▼
┌─────────────────────────────────┐
│ WEB INTERFACE │
│ • Drag & Drop Upload │
│ • File Validation │
│ • UI Feedback │
└──────┬──────────────────────────┘
│
▼
┌─────────────────────────────────┐
│ PREPROCESSING │
│ • Resize: 640×640 │
│ • Normalize: [0-1] │
│ • Color: BGR→RGB │
│ • Format: HWC→CHW │
└──────┬──────────────────────────┘
│
▼
┌─────────────────────────────────┐
│ ONNX INFERENCE ENGINE │
│ • Load Model │
│ • Run Prediction │
│ • Extract Features │
└──────┬──────────────────────────┘
│
▼
┌─────────────────────────────────┐
│ POST-PROCESSING │
│ • Parse Predictions │
│ • Filter (Conf > 25%) │
│ • Scale Coordinates │
│ • Class Mapping │
└──────┬──────────────────────────┘
│
▼
┌─────────────────────────────────┐
│ VISUALIZATION │
│ • Text Overlay │
│ • Confidence Scores │
│ • Detection Summary │
└──────┬──────────────────────────┘
│
▼
┌─────────────────────────────────┐
│ RESPONSE TO USER │
│ • Annotated Media │
│ • Statistics Table │
│ • Download Option │
└─────────────────────────────────┘
- Upload - User uploads image/video
- Preprocessing - Resize to 640×640, normalize, convert to tensor
- Inference - YOLO ONNX model detects behaviors
- Post-processing - Parse predictions, filter by confidence threshold
- Visualization - Overlay text labels with confidence scores
- Response - Return annotated media with statistics
Prerequisites:
- Python 3.12+
- ONNX Runtime
Setup:
# Clone repository
git clone https://github.com/07fahim/Driver-Distraction-Detection-and-Classification.git
cd Driver-Distraction-Detection-and-Classification
# Switch to main branch
git checkout main
# Navigate to deployment folder
cd deployment
# Install dependencies
pip install -r requirements.txt
# Run Gradio app
python app.pyAccess at: http://localhost:7860
Prerequisites:
- Python 3.12+
- Docker (optional)
Local Setup:
# Clone repository
git clone https://github.com/07fahim/Driver-Distraction-Detection-and-Classification.git
cd Driver-Distraction-Detection-and-Classification
# Switch to flask branch
git checkout flask
# Install dependencies
pip install -r requirements.txt
# Run Flask app
python app.pyAccess at: http://localhost:5000
Docker Setup:
# Build image
docker build -t safedrive-ai .
# Run container
docker run -p 5000:5000 safedrive-aiFeatures:
- Upload images or videos via drag-and-drop
- Real-time detection with confidence scores
- Interactive results visualization
- Detection summary tables
- Webcam support for live detection
Available Pages:
- Home - Overview and features
- Image Detection - Upload and analyze images
- Video Detection - Process video files
- About - Technical details and documentation
API Endpoints:
| Endpoint | Method | Description |
|---|---|---|
/api/detect-image |
POST | Upload image for detection |
/api/detect-video |
POST | Upload video for processing |
/api/download-video/<id> |
GET | Download processed video |
Response Format:
Image detection returns JSON with annotated image (base64) and detection list including class names and confidence scores.
Video detection returns JSON with video ID and summary statistics including total detections, average confidence, frame ranges, and duration per behavior.
Platform: Hugging Face Spaces
Repository: main branch, deployment/ folder
Runtime: Python 3.12 with ONNX Runtime
Deployment Process:
- Code pushed to
mainbranch triggers automatic rebuild - Hugging Face Spaces pulls latest changes
- Dependencies installed from requirements.txt
- ONNX model weights loaded from repository
- Gradio application starts on port 7860
- Public URL becomes accessible
Configuration:
- Automatic rebuilds on push
- Model inference via ONNX Runtime CPU
- Public access with no authentication required
Platform: Render.com
Repository: flask branch
Container: Docker with Python 3.12-slim base
Web Server: Gunicorn with 2 workers, 300-second timeout
CI/CD: GitHub Actions automated deployment
Live URL: https://driver-distraction-detection-and.onrender.com
Deployment Process:
- Code pushed to
flaskbranch - GitHub Actions workflow triggered
- Render API called with deploy hook
- Docker image built from Dockerfile
- Application deployed with Gunicorn
- Health checks verify successful deployment
Infrastructure:
- Docker containerization for consistency
- Gunicorn WSGI server for production
- Automatic file cleanup after 1 hour
- 100MB maximum file upload size
- /tmp directories for file processing
GitHub Actions Workflow:
Automated deployment configured in .github/workflows/deploy.yml with triggers on push to flask branch, Render API integration, and automatic cache clearing.
Environment Configuration:
Required secrets in GitHub repository settings:
RENDER_API_KEY- Render API authenticationRENDER_SERVICE_ID- Target service identifier
safedrive-ai/
│
├── main/ # Main branch
│ ├── notebooks/ # Model training
│ │ ├── detection/
│ │ │ ├── yolov10n.ipynb
│ │ │ ├── yolov10s.ipynb
│ │ │ ├── yolov10m.ipynb
│ │ │ └── yolov10l.ipynb
│ │ └── classification/
│ │ ├── convnext-tiny.ipynb
│ │ ├── efficientnet-b0.ipynb
│ │ ├── mobilenetv2.ipynb
│ │ ├── resnet50.ipynb
│ │ └── vgg19.ipynb
│ └── deployment/ # Gradio app
│ ├── app.py
│ ├── best.onnx
│ └── requirements.txt
│
├── flask/ # Flask branch
│ ├── app.py # Flask application
│ ├── templates/ # HTML templates
│ │ ├── index.html
│ │ ├── image.html
│ │ ├── video.html
│ │ └── about.html
│ ├── static/css/ # Stylesheets
│ │ ├── style.css
│ │ ├── home.css
│ │ ├── detection.css
│ │ └── analysis.css
│ ├── Dockerfile
│ ├── requirements.txt
│ ├── gunicorn.conf.py
│ └── .github/workflows/
│ └── deploy.yml
│
└── README.md
Deep Learning & AI
- YOLO (You Only Look Once) - Object detection
- ONNX Runtime - Cross-platform inference
- OpenCV - Computer vision
- NumPy - Numerical computing
Web Frameworks
- Flask 3.0.0 - Backend framework
- Gradio - ML interface framework
- Gunicorn - WSGI HTTP server
Frontend
- HTML5/CSS3 - Modern web standards
- JavaScript - Interactive features
- Font Awesome - Icon library
DevOps & Deployment
- Docker - Containerization
- GitHub Actions - CI/CD automation
- Render.com - Cloud hosting
- Hugging Face Spaces - ML deployment
Development Tools
- Python 3.12 - Programming language
- Git - Version control
- Jupyter Notebooks - Experimentation
Contributions are welcome. Please follow these steps:
- Fork the repository
- Create a feature branch (
git checkout -b feature/YourFeature) - Commit changes (
git commit -m 'Add YourFeature') - Push to branch (
git push origin feature/YourFeature) - Open a Pull Request
- Follow PEP 8 style guide
- Add unit tests for new features
- Update documentation
- Ensure CI/CD pipeline passes
This project is licensed under the MIT License - see the LICENSE file for details.
Project Maintainer: Fahim Faiyaz
- Email: faiyazfahim743@gmail.com
- LinkedIn: https://www.linkedin.com/in/fahim-faiyaz
- GitHub: https://github.com/07fahim
Project Links:
- Repository: https://github.com/07fahim/Driver-Distraction-Detection-and-Classification
- Gradio App: https://huggingface.co/spaces/yeager07/distracted-driving-detection
- Flask App: https://driver-distraction-detection-and.onrender.com
- Dataset: Roboflow Universe
- Dataset provided by FlyTech team on Roboflow Universe
- YOLO models from Ultralytics YOLOv10
- Deployment platforms: Hugging Face Spaces and Render.com
- Open-source community for tools and libraries
Last Updated: January 2025
Status: Production Ready



