# syrajveer/anti-accident-detection-model architecture

> Architecture diagram of the GitHub repository syrajveer/anti-accident-detection-model, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/syrajveer/anti-accident-detection-model
- Repository: https://github.com/syrajveer/anti-accident-detection-model

## Overview

##### Project type and purpose
- This is a full‑stack, Deep‑Learning‑powered warning system for detecting driver inattention or dangerous behavior in real time.
- The Python/Flask “backend” hosts endpoints that accept a video stream or file, run a trained InceptionV3‐based model plus computer‐vision routines, and return warnings. The “frontend” is a simple web UI (HTML/CSS/ JS) that streams video, displays alerts, and plays an alarm sound.

##### File structure
- Top‑level application:
- app.py – Flask app defining HTTP routes, loading models, orchestrating inference.
- inceptionv3.h5 / inceptionv3.pkl – trained Deep Learning model files.
- model.js – client‑side JavaScript (likely handles video capture/streaming).
- alarm.wav – audio alert resource.
- requirements.txt – Python dependencies (Flask, Keras, OpenCV, etc.).
- Templates directory:
- index.html – main UI page.
- style.css – styling.
- Test_Video_s.mp4 – sample video for local testing.
- Notebooks: main_Code.ipynb – data exploration, model training pipeline.
- Configuration: LICENSE, README, PPTX demo.

##### Key architectural insights from README
- System ingests live or uploaded dashboard camera feed.
- Pipeline combines face detection, eye tracking, head‐pose estimation, feeding features to a Deep Neural Network.
- Outputs real‑time alerts (visual + alarm.wav).
- No external database; state is ephemeral per session.

##### Main components
a. Frontend (Browser)
- HTML/CSS (templates/index.html, style.css)
- JavaScript (model.js) for video capture, streaming to backend, rendering results, playing alarm.wav
b. Backend (Flask)
- app.py orchestrates endpoints:
- / → serves index.html
- /predict (or similar) → accepts video frames or file via HTTP POST/WebSocket
- Preprocessing modules (OpenCV) for face/eye/head‐pose extraction
- Model inference module (loads inceptionv3.h5/.pkl via Keras)
c. Machine Learning Model
- InceptionV3‐based network for classification of “safe” vs “attention‐required” states
d. Notification subsystem
- Alarm.wav triggered by the frontend or backend event
e. (Optional) Training Pipeline
- Jupyter notebook showing data collection, preprocessing, training steps

##### Relationships and data flows
- Browser captures video → streams frames via HTTP/WebSocket → Flask receives frames → OpenCV face/eye/head‐pose processing → feature tensor → Keras model inference → classification result back to frontend → UI updates overlay + plays alarm.wav
- For testing: frontend can POST Test_Video_s.mp4 instead of live camera.
- No persistent storage or external services; purely synchronous request/response.

##### Architectural patterns & design principles
- MVC/lightweight “view” in templates, “controller” in app.py, “model” in Keras code
- Separation of concerns:
- Presentation (HTML/CSS/JS)
- Application logic (Flask routes)
- ML logic (preprocessing + inference)
- Single‑process, single Docker/container potential deployment (not microservices).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client Layer"
        Camera["Camera"]:::frontend
        Browser["Browser UI"]:::frontend
        HTML["HTML Template (index.html)"]:::frontend
        CSS["CSS Stylesheet (style.css)"]:::frontend
        JS["JavaScript (model.js)"]:::frontend
        Alarm["Alarm Audio (alarm.wav)"]:::frontend
        TestVideo["Test Video (Test_Video_s.mp4)"]:::frontend
    end

    %% Application Layer
    subgraph "Application Layer"
        Flask["Flask Server (app.py)"]:::backend
        Requirements["requirements.txt"]:::backend
    end

    %% ML Layer
    subgraph "ML Layer"
        subgraph "Preprocessing"
            Face["Face Detection"]:::ml
            Eye["Eye Tracking"]:::ml
            Head["Head-Pose Estimation"]:::ml
        end
        subgraph "Inference"
            ModelFile1[(inceptionv3.h5)]:::ml
            ModelFile2[(inceptionv3.pkl)]:::ml
            Inference["Keras Model Inference"]:::ml
        end
    end

    %% Training Pipeline
    Notebook["Jupyter Notebook (main_Code.ipynb)"]:::ml

    %% Data Flows
    Camera -->|"raw video"| Browser
    Browser -->|"video frames"| Flask
    TestVideo -->|"video file"| Flask
    Flask -->|"raw frames"| Face
    Face -->|"bounding boxes"| Eye
    Eye -->|"eye data"| Head
    Head -->|"feature tensor"| Inference
    Inference -->|"classification result"| Flask
    Flask -->|"result JSON"| Browser
    Browser -->|"play alarm"| Alarm

    Notebook -->|"exports model files"| ModelFile1
    Notebook --> ModelFile2

    %% Click Events
    click HTML "https://github.com/syrajveer/anti-accident-detection-model/blob/main/templates/index.html"
    click CSS "https://github.com/syrajveer/anti-accident-detection-model/blob/main/templates/style.css"
    click JS "https://github.com/syrajveer/anti-accident-detection-model/blob/main/model.js"
    click Alarm "https://github.com/syrajveer/anti-accident-detection-model/blob/main/alarm.wav"
    click TestVideo "https://github.com/syrajveer/anti-accident-detection-model/blob/main/templates/Test_Video_s.mp4"
    click Flask "https://github.com/syrajveer/anti-accident-detection-model/blob/main/app.py"
    click Requirements "https://github.com/syrajveer/anti-accident-detection-model/blob/main/requirements.txt"
    click ModelFile1 "https://github.com/syrajveer/anti-accident-detection-model/blob/main/inceptionv3.h5"
    click ModelFile2 "https://github.com/syrajveer/anti-accident-detection-model/blob/main/inceptionv3.pkl"
    click Notebook "https://github.com/syrajveer/anti-accident-detection-model/blob/main/main_Code.ipynb"

    %% Styling
    classDef frontend fill:#b3cde0,stroke:#3182bd,color:#000;
    classDef backend fill:#ccebc5,stroke:#31a354,color:#000;
    classDef ml fill:#fdae61,stroke:#e6550d,color:#000;
```
