Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

66 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

DriveSafe πŸš—πŸ›‘οΈ

Real-Time AI-Powered Advanced Driver Assistance System (ADAS) for Indian Roads

Python 3.11 FastAPI React 19 Vite 8 Tailwind CSS 4 YOLO11m MiDaS MediaPipe License MIT


✨ Features β€’ πŸ—οΈ Architecture β€’ βš™οΈ Tech Stack β€’ πŸš€ Quick Start β€’ πŸ“Έ Dashboard β€’ πŸ“ Project Structure β€’ 🧠 Models β€’ 🌐 Deployment


✨ Features

πŸ›£οΈ Road Hazard Detection (Forward Camera)

  • Custom YOLO11m fine-tuned on BDD100K, IDD (Indian Driving Dataset), and DAWN (weather-degraded) datasets
  • Detects vehicles, pedestrians, cattle, auto-rickshaws, motorcycles, and stray animals
  • MiDaS monocular depth estimation for distance perception without LiDAR
  • Indian road danger weighting β€” objects are scored by class-specific weights (e.g., pedestrian/cow = 1.0, car = 0.6)

πŸ‘€ Driver Monitoring (Cabin Camera)

  • MediaPipe Face Landmarker (468-point facial mesh) for precise face tracking
  • EAR (Eye Aspect Ratio) β€” real-time drowsiness detection
  • PERCLOS β€” percentage of eyelid closure over time
  • MAR (Mouth Aspect Ratio) β€” yawn detection
  • 6-DoF Head Pose Estimation β€” distraction and head nod detection

🧠 Risk Fusion Engine

  • Dual-stream fusion: 40% road hazard + 60% driver state β†’ unified risk score
  • Risk levels: LOW 🟒 / MEDIUM 🟑 / CRITICAL πŸ”΄
  • Real-time WebSocket streaming to live dashboard

πŸŽ›οΈ Interactive Dashboard

  • Side-by-side video panels with annotation overlays
  • Live risk score bars and rolling analytics charts
  • Alert feed with animated entries
  • Upload road/cabin videos for batch processing

πŸ—οΈ Architecture

Road Camera (forward-facing)          Cabin Camera (driver-facing)
         |                                      |
         v                                      v
   [YOLO11m Detection]              [MediaPipe Face Landmarks]
   (vehicles, cattle,                (468-point facial mesh)
    pedestrians, auto-rickshaws)            |
         |                              +----+----+
         v                              |    |    |
   [MiDaS Depth Estimation]        [EAR] [MAR] [PERCLOS]
   (monocular depth map)              |    |    |
         |                           [Head Pose] [Nod Detection]
         v                            |          |
   [Indian Road Danger                v          v
    Weighting Algorithm]         [Driver State Fusion]
   (object class x proximity)      (weighted: 30% EAR, 25% PERCLOS,
         |                          20% MAR, 15% nod, 10% pose)
         v                              |
   [Road Hazard Score]                  |
         |                              |
         +----------+-------------------+
                    |
                    v
           [Risk Fusion Engine]
           (40% road + 60% driver)
                    |
                    v
          [Unified Risk Score]
          (LOW / MEDIUM / CRITICAL)
                    |
                    v
          [WebSocket Stream]
          + [Annotated Video Output]

βš™οΈ Tech Stack

Backend

Component Technology
Language Python 3.11
Web Framework FastAPI (async)
ASGI Server Uvicorn
Real-time WebSockets
Object Detection Ultralytics YOLO11m (fine-tuned)
Depth Estimation MiDaS (MiDaS_small)
Face Tracking MediaPipe Face Landmarker
Computer Vision OpenCV, NumPy, SciPy
ML Framework PyTorch

Frontend

Component Technology
Language JavaScript (ES Modules)
UI Framework React 19
Build Tool Vite 8
Styling Tailwind CSS v4
Animation Framer Motion
Charting Recharts
Icons Lucide React
Linting ESLint 10

πŸš€ Quick Start

Backend Setup

cd backend

# Create virtual environment
python -m venv venv
source venv/bin/activate  # Linux/Mac
# .\venv\Scripts\Activate  # Windows

# Install dependencies
pip install -r requirements.txt

# Download model weights
python download_weights.py

# Run server
uvicorn app.main:app --reload --host 0.0.0.0 --port 8000

Frontend Setup

cd frontend

# Install dependencies
npm install

# Set backend URL (optional, defaults to localhost:8000)
echo "VITE_API_URL=http://localhost:8000" > .env

# Run development server
npm run dev

Open http://localhost:5173 in your browser.

Docker (Backend)

cd backend
docker build -t drivesafe-backend .
docker run -p 7860:7860 drivesafe-backend

πŸ“Έ Dashboard

The DriveSafe dashboard is a futuristic HUD-style interface featuring:

  • Dual Video Panels β€” side-by-side road (left) and driver (right) feeds with real-time annotations
  • Control Panel β€” upload road/cabin videos, Run/Stop/Reset analysis
  • Risk Badge β€” animated LOW/MEDIUM/CRITICAL indicator
  • Score Panel β€” live road hazard score, driver state score, and fused risk score
  • Analytics Chart β€” rolling time-series of all three scores
  • Alert Feed β€” real-time alerts for detected events (drowsiness, yawning, objects, etc.)

πŸ“ Project Structure

DriveSafe/
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ app/
β”‚   β”‚   β”œβ”€β”€ main.py                    # FastAPI entry point & routes
β”‚   β”‚   β”œβ”€β”€ config.py                  # Environment configuration
β”‚   β”‚   β”œβ”€β”€ annotators/                # Frame annotation overlays
β”‚   β”‚   β”œβ”€β”€ models/
β”‚   β”‚   β”‚   β”œβ”€β”€ yolo/                  # YOLO11m detection pipeline
β”‚   β”‚   β”‚   β”œβ”€β”€ depth/                 # MiDaS depth estimation
β”‚   β”‚   β”‚   └── driver/                # MediaPipe face & metrics
β”‚   β”‚   β”œβ”€β”€ processors/                # Processing pipeline orchestrators
β”‚   β”‚   β”œβ”€β”€ websocket/                 # WebSocket real-time streaming
β”‚   β”‚   └── utils/                     # Image utilities
β”‚   β”œβ”€β”€ weights/                       # Model weight files
β”‚   β”œβ”€β”€ requirements.txt               # Python dependencies
β”‚   β”œβ”€β”€ requirements-hf.txt            # HuggingFace-optimized deps
β”‚   β”œβ”€β”€ Dockerfile                     # Multi-stage Docker build
β”‚   └── download_weights.py            # Weights downloader
β”‚
└── frontend/
    β”œβ”€β”€ src/
    β”‚   β”œβ”€β”€ pages/                     # Page components
    β”‚   β”œβ”€β”€ sections/                  # Landing page sections
    β”‚   β”œβ”€β”€ components/
    β”‚   β”‚   β”œβ”€β”€ dashboard/             # Live dashboard components
    β”‚   β”‚   β”œβ”€β”€ analytics/             # Score & chart components
    β”‚   β”‚   β”œβ”€β”€ cards/                 # Reusable card components
    β”‚   β”‚   β”œβ”€β”€ ui/                    # Base UI primitives
    β”‚   β”‚   β”œβ”€β”€ hero/                  # Hero section components
    β”‚   β”‚   └── layout/                # Navbar & layout
    β”‚   β”œβ”€β”€ services/api.js            # REST + WebSocket client
    β”‚   └── styles/globals.css         # Tailwind v4 theme
    β”œβ”€β”€ package.json                   # NPM dependencies
    β”œβ”€β”€ vite.config.js                 # Vite configuration
    β”œβ”€β”€ vercel.json                    # Vercel deployment
    └── .env.example                   # Environment template

🧠 Models

Model Source Purpose
YOLO11m (fine-tuned) Ultralytics + custom training on BDD100K, IDD, DAWN Object detection for Indian road hazards
MiDaS_small Intel ISL (torch.hub) Monocular depth estimation
FaceLandmarker Google MediaPipe 468-point facial landmark detection

Weights are downloaded automatically via download_weights.py.


🌐 Deployment

Frontend (Vercel)

The frontend includes a vercel.json for SPA deployment:

cd frontend
npm run build
vercel --prod

Backend (Hugging Face Spaces)

The backend includes a Dockerfile configured for Hugging Face Spaces with sdk: docker.


πŸ›£οΈ Roadmap

  • Real-time camera input (USB/RTSP) in addition to video upload
  • Multi-session concurrent processing with isolated driver state
  • Unit & integration tests
  • Mobile companion app
  • On-device edge deployment (NVIDIA Jetson / Raspberry Pi)
  • Additional Indian-specific hazard classes (speed bumps, potholes)

πŸ“„ License

MIT

About

Real-time AI-powered Advanced Driver Assistance System (ADAS) for Indian roads. Dual-stream pipeline using YOLO11m + MiDaS for road hazard detection and MediaPipe for driver drowsiness/distraction monitoring, fused into a unified risk score with a live WebSocket dashboard. Built with FastAPI + React.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages