# ali-asif-git/driver-drowsiness-detection architecture

> Architecture diagram of the GitHub repository ali-asif-git/driver-drowsiness-detection, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ali-asif-git/driver-drowsiness-detection
- Repository: https://github.com/ali-asif-git/driver-drowsiness-detection

## Overview

This repository provides driver drowsiness and distraction detection for images, video files, and live webcams, plus a documented YOLOv8 training workflow. Inference entry points load the trained weights and use shared helpers for prediction, annotation, and stream display or saving. The training stages are described in the README and represented by the training notebook; their internal implementation was not sampled, so those relationships are cited to the README rather than inferred from source. This graph covers documented capabilities, not temporal alerting or other future work.

Main entry points: [`src/utils.py`](https://github.com/ali-asif-git/driver-drowsiness-detection/blob/main/src/utils.py) (Stream processor), [`src/detect_image.py`](https://github.com/ali-asif-git/driver-drowsiness-detection/blob/main/src/detect_image.py) (Image runner), [`notebooks/YOLOv8_training.ipynb`](https://github.com/ali-asif-git/driver-drowsiness-detection/blob/main/notebooks/YOLOv8_training.ipynb) (YOLOv8 training), [`weights`](https://github.com/ali-asif-git/driver-drowsiness-detection/tree/main/weights) (Trained weights)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_inference["Inference inputs"]
  node_image_runner["Image runner<br/>[detect_image.py]"]
  node_video_runner["Video runner<br/>[detect_video.py]"]
  node_webcam_runner["Webcam runner<br/>[detect_webcam.py]"]
  node_input_media["Input media"]
  node_output_media["Displayed or saved output"]
end

subgraph group_runtime["Detection runtime"]
  node_stream_helper["Stream processor<br/>[utils.py]"]
  node_annotator["Detection annotator<br/>[utils.py]"]
  node_yolo["YOLOv8 inference"]
end

subgraph group_training["Model training"]
  node_dataset["Annotated dataset<br/>[data.yaml]"]
  node_training_workflow["YOLOv8 training"]
  node_evaluation["Model evaluation"]
end

subgraph group_artifacts["Model artifacts"]
  node_weights[("Trained weights")]
end

node_image_user(("Image user"))
node_video_user(("Video user"))
node_webcam_user(("Webcam user"))
node_annotator_service["Roboflow"]
node_colab["Colab GPU"]

node_image_user -->|"runs"| node_image_runner
node_video_user -->|"runs"| node_video_runner
node_webcam_user -->|"runs"| node_webcam_runner
node_image_runner -->|"reads"| node_input_media
node_image_runner -->|"runs inference"| node_yolo
node_image_runner -->|"calls"| node_annotator
node_video_runner -->|"calls"| node_stream_helper
node_webcam_runner -->|"calls"| node_stream_helper
node_stream_helper -->|"captures frames"| node_input_media
node_stream_helper -->|"runs inference"| node_yolo
node_stream_helper -->|"calls"| node_annotator
node_annotator -->|"draws labels"| node_output_media
node_image_runner -->|"saves or displays"| node_output_media
node_stream_helper -->|"displays or saves"| node_output_media
node_image_runner -->|"loads"| node_weights
node_stream_helper -->|"loads"| node_weights
node_dataset -->|"annotated with"| node_annotator_service
node_dataset -->|"exported for"| node_training_workflow
node_training_workflow -->|"runs on"| node_colab
node_training_workflow -->|"evaluates"| node_evaluation
node_evaluation -->|"produces best.pt"| node_weights

click node_image_runner "https://github.com/ali-asif-git/driver-drowsiness-detection/blob/main/src/detect_image.py"
click node_video_runner "https://github.com/ali-asif-git/driver-drowsiness-detection/blob/main/src/detect_video.py"
click node_webcam_runner "https://github.com/ali-asif-git/driver-drowsiness-detection/blob/main/src/detect_webcam.py"
click node_stream_helper "https://github.com/ali-asif-git/driver-drowsiness-detection/blob/main/src/utils.py"
click node_annotator "https://github.com/ali-asif-git/driver-drowsiness-detection/blob/main/src/utils.py"
click node_dataset "https://github.com/ali-asif-git/driver-drowsiness-detection/blob/main/data.yaml"
click node_training_workflow "https://github.com/ali-asif-git/driver-drowsiness-detection/blob/main/notebooks/YOLOv8_training.ipynb"
click node_evaluation "https://github.com/ali-asif-git/driver-drowsiness-detection/blob/main/notebooks/YOLOv8_training.ipynb"
click node_weights "https://github.com/ali-asif-git/driver-drowsiness-detection/tree/main/weights"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_image_runner,node_video_runner,node_webcam_runner,node_input_media,node_output_media,node_image_user,node_video_user,node_webcam_user toneBlue
class node_stream_helper,node_annotator,node_yolo toneAmber
class node_dataset,node_training_workflow,node_evaluation toneMint
class node_weights toneRose
class node_annotator_service,node_colab toneIndigo
```

## Components

### Inference inputs

- [Image runner](https://github.com/ali-asif-git/driver-drowsiness-detection/blob/main/src/detect_image.py): `src/detect_image.py`
- [Video runner](https://github.com/ali-asif-git/driver-drowsiness-detection/blob/main/src/detect_video.py): `src/detect_video.py`
- [Webcam runner](https://github.com/ali-asif-git/driver-drowsiness-detection/blob/main/src/detect_webcam.py): `src/detect_webcam.py`
- **Input media**
- **Displayed or saved output**

### Detection runtime

- [Stream processor](https://github.com/ali-asif-git/driver-drowsiness-detection/blob/main/src/utils.py): `src/utils.py`
- [Detection annotator](https://github.com/ali-asif-git/driver-drowsiness-detection/blob/main/src/utils.py): `src/utils.py`
- **YOLOv8 inference**

### Model training

- [Annotated dataset](https://github.com/ali-asif-git/driver-drowsiness-detection/blob/main/data.yaml): `data.yaml`
- [YOLOv8 training](https://github.com/ali-asif-git/driver-drowsiness-detection/blob/main/notebooks/YOLOv8_training.ipynb): `notebooks/YOLOv8_training.ipynb`
- [Model evaluation](https://github.com/ali-asif-git/driver-drowsiness-detection/blob/main/notebooks/YOLOv8_training.ipynb): `notebooks/YOLOv8_training.ipynb`

### Model artifacts

- [Trained weights](https://github.com/ali-asif-git/driver-drowsiness-detection/tree/main/weights): `weights`

### Other components

- **Image user**
- **Video user**
- **Webcam user**
- **Roboflow**
- **Colab GPU**

## Connections

- Image user → Image runner: runs (evidence: `README.md`)
- Video user → Video runner: runs (evidence: `README.md`)
- Webcam user → Webcam runner: runs (evidence: `README.md`)
- Image runner → Input media: reads (evidence: `src/detect_image.py`)
- Image runner → YOLOv8 inference: runs inference (evidence: `src/detect_image.py`)
- Image runner → Detection annotator: calls (evidence: `src/detect_image.py`)
- Video runner → Stream processor: calls (evidence: `src/detect_video.py`)
- Webcam runner → Stream processor: calls (evidence: `src/detect_webcam.py`)
- Stream processor → Input media: captures frames (evidence: `src/utils.py`)
- Stream processor → YOLOv8 inference: runs inference (evidence: `src/utils.py`)
- Stream processor → Detection annotator: calls (evidence: `src/utils.py`)
- Detection annotator → Displayed or saved output: draws labels (evidence: `src/utils.py`)
- Image runner → Displayed or saved output: saves or displays (evidence: `src/detect_image.py`)
- Stream processor → Displayed or saved output: displays or saves (evidence: `src/utils.py`)
- Image runner → Trained weights: loads (evidence: `src/detect_image.py`)
- Stream processor → Trained weights: loads (evidence: `src/utils.py`)
- Annotated dataset → Roboflow: annotated with (evidence: `README.md`)
- Annotated dataset → YOLOv8 training: exported for (evidence: `README.md`)
- YOLOv8 training → Colab GPU: runs on (evidence: `README.md`)
- YOLOv8 training → Model evaluation: evaluates (evidence: `README.md`)
- Model evaluation → Trained weights: produces best.pt (evidence: `README.md`)
