# b23mt1033/real-time-facemask-detection architecture

> Architecture diagram of the GitHub repository b23mt1033/real-time-facemask-detection, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/b23mt1033/real-time-facemask-detection
- Repository: https://github.com/b23mt1033/real-time-facemask-detection

## Overview

This repository implements real-time face-mask detection for webcam frames and still images. The interactive workflow selects an input and model mode, detects faces (or uses YOLO directly), classifies mask status, and displays annotated results. ResNet and YOLO inference can also contribute to an ensemble. The available excerpts establish several dispatch and inference relationships; some frame-processing details are omitted, so those links are not inferred.

Main entry points: [`realtime.py`](https://github.com/b23mt1033/real-time-facemask-detection/blob/main/realtime.py) (Interactive Menu), [`deploy.prototxt`](https://github.com/b23mt1033/real-time-facemask-detection/blob/main/deploy.prototxt) (Caffe Detector Config), [`res10_300x300_ssd_iter_140000.caffemodel`](https://github.com/b23mt1033/real-time-facemask-detection/blob/main/res10_300x300_ssd_iter_140000.caffemodel) (Caffe Detector Weights), [`yolo_v8.pt`](https://github.com/b23mt1033/real-time-facemask-detection/blob/main/yolo_v8.pt) (YOLO Model)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Input and Runtime"]
  node_interactive["Interactive Menu<br/>[realtime.py]"]
  node_image_input["Image Input<br/>[realtime.py]"]
  node_frame_loop["Webcam Loop<br/>[realtime.py]"]
  node_frame_router["Frame Mode Router<br/>[realtime.py]"]
  node_result_display["Result Display<br/>[realtime.py]"]
end

subgraph group_detection["Face Detection"]
  node_caffe_frame["Caffe Frame Processing<br/>[realtime.py]"]
  node_face_detector["Face Detector<br/>[realtime.py]"]
  node_yolo_frame["YOLO Frame Processing<br/>[realtime.py]"]
end

subgraph group_classification["Mask Classification"]
  node_resnet_predict["ResNet Prediction<br/>[realtime.py]"]
  node_ensemble["Ensemble Voting<br/>[realtime.py]"]
end

subgraph group_assets["Model Assets"]
  node_face_model_config["Caffe Detector Config<br/>[deploy.prototxt]"]
  node_face_model_weights["Caffe Detector Weights"]
  node_yolo_model["YOLO Model<br/>[yolo_v8.pt]"]
  node_resnet18_weights["ResNet-18 Weights"]
  node_resnet50_weights["ResNet-50 Weights"]
end

node_user(("User"))
node_camera(("Webcam"))

node_user -->|"selects mode"| node_interactive
node_interactive -->|"starts webcam"| node_frame_loop
node_camera -->|"supplies frames"| node_frame_loop
node_interactive -->|"selects image"| node_image_input
node_image_input -->|"dispatches image"| node_frame_router
node_frame_loop -->|"dispatches frames"| node_frame_router
node_frame_router -->|"selects YOLO mode"| node_yolo_frame
node_frame_router -->|"selects other modes"| node_caffe_frame
node_caffe_frame -->|"runs detection"| node_face_detector
node_face_detector -->|"loads config"| node_face_model_config
node_face_detector -->|"loads weights"| node_face_model_weights
node_yolo_frame -->|"runs inference"| node_yolo_model
node_resnet_predict -->|"loads when selected"| node_resnet18_weights
node_resnet_predict -->|"loads when selected"| node_resnet50_weights
node_ensemble -->|"collects predictions"| node_resnet_predict
node_ensemble -->|"uses YOLO prediction"| node_yolo_frame
node_interactive -->|"shows image result"| node_result_display
node_frame_loop -->|"displays frames"| node_result_display

click node_interactive "https://github.com/b23mt1033/real-time-facemask-detection/blob/main/realtime.py"
click node_image_input "https://github.com/b23mt1033/real-time-facemask-detection/blob/main/realtime.py"
click node_frame_loop "https://github.com/b23mt1033/real-time-facemask-detection/blob/main/realtime.py"
click node_frame_router "https://github.com/b23mt1033/real-time-facemask-detection/blob/main/realtime.py"
click node_caffe_frame "https://github.com/b23mt1033/real-time-facemask-detection/blob/main/realtime.py"
click node_face_detector "https://github.com/b23mt1033/real-time-facemask-detection/blob/main/realtime.py"
click node_face_model_config "https://github.com/b23mt1033/real-time-facemask-detection/blob/main/deploy.prototxt"
click node_face_model_weights "https://github.com/b23mt1033/real-time-facemask-detection/blob/main/res10_300x300_ssd_iter_140000.caffemodel"
click node_yolo_frame "https://github.com/b23mt1033/real-time-facemask-detection/blob/main/realtime.py"
click node_yolo_model "https://github.com/b23mt1033/real-time-facemask-detection/blob/main/yolo_v8.pt"
click node_resnet_predict "https://github.com/b23mt1033/real-time-facemask-detection/blob/main/realtime.py"
click node_resnet18_weights "https://github.com/b23mt1033/real-time-facemask-detection/blob/main/saved_models/model_resnet18_state_dict.pth"
click node_resnet50_weights "https://github.com/b23mt1033/real-time-facemask-detection/blob/main/saved_models/model_resnet50_state_dict.pth"
click node_ensemble "https://github.com/b23mt1033/real-time-facemask-detection/blob/main/realtime.py"
click node_result_display "https://github.com/b23mt1033/real-time-facemask-detection/blob/main/realtime.py"

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_interactive,node_image_input,node_frame_loop,node_frame_router,node_result_display,node_user toneBlue
class node_caffe_frame,node_face_detector,node_yolo_frame toneAmber
class node_resnet_predict,node_ensemble toneMint
class node_face_model_config,node_face_model_weights,node_yolo_model,node_resnet18_weights,node_resnet50_weights toneRose
class node_camera toneIndigo
```

## Components

### Input and Runtime

- [Interactive Menu](https://github.com/b23mt1033/real-time-facemask-detection/blob/main/realtime.py): `realtime.py`
- [Image Input](https://github.com/b23mt1033/real-time-facemask-detection/blob/main/realtime.py): `realtime.py`
- [Webcam Loop](https://github.com/b23mt1033/real-time-facemask-detection/blob/main/realtime.py): `realtime.py`
- [Frame Mode Router](https://github.com/b23mt1033/real-time-facemask-detection/blob/main/realtime.py): `realtime.py`
- [Result Display](https://github.com/b23mt1033/real-time-facemask-detection/blob/main/realtime.py): `realtime.py`

### Face Detection

- [Caffe Frame Processing](https://github.com/b23mt1033/real-time-facemask-detection/blob/main/realtime.py): `realtime.py`
- [Face Detector](https://github.com/b23mt1033/real-time-facemask-detection/blob/main/realtime.py): `realtime.py`
- [YOLO Frame Processing](https://github.com/b23mt1033/real-time-facemask-detection/blob/main/realtime.py): `realtime.py`

### Mask Classification

- [ResNet Prediction](https://github.com/b23mt1033/real-time-facemask-detection/blob/main/realtime.py): `realtime.py`
- [Ensemble Voting](https://github.com/b23mt1033/real-time-facemask-detection/blob/main/realtime.py): `realtime.py`

### Model Assets

- [Caffe Detector Config](https://github.com/b23mt1033/real-time-facemask-detection/blob/main/deploy.prototxt): `deploy.prototxt`
- [Caffe Detector Weights](https://github.com/b23mt1033/real-time-facemask-detection/blob/main/res10_300x300_ssd_iter_140000.caffemodel): `res10_300x300_ssd_iter_140000.caffemodel`
- [YOLO Model](https://github.com/b23mt1033/real-time-facemask-detection/blob/main/yolo_v8.pt): `yolo_v8.pt`
- [ResNet-18 Weights](https://github.com/b23mt1033/real-time-facemask-detection/blob/main/saved_models/model_resnet18_state_dict.pth): `saved_models/model_resnet18_state_dict.pth`
- [ResNet-50 Weights](https://github.com/b23mt1033/real-time-facemask-detection/blob/main/saved_models/model_resnet50_state_dict.pth): `saved_models/model_resnet50_state_dict.pth`

### Other components

- **User**
- **Webcam**

## Connections

- User → Interactive Menu: selects mode (evidence: `realtime.py`)
- Interactive Menu → Webcam Loop: starts webcam (evidence: `realtime.py`)
- Webcam → Webcam Loop: supplies frames (evidence: `realtime.py`)
- Interactive Menu → Image Input: selects image (evidence: `realtime.py`)
- Image Input → Frame Mode Router: dispatches image (evidence: `realtime.py`)
- Webcam Loop → Frame Mode Router: dispatches frames (evidence: `realtime.py`)
- Frame Mode Router → YOLO Frame Processing: selects YOLO mode (evidence: `realtime.py`)
- Frame Mode Router → Caffe Frame Processing: selects other modes (evidence: `realtime.py`)
- Caffe Frame Processing → Face Detector: runs detection (evidence: `realtime.py`)
- Face Detector → Caffe Detector Config: loads config (evidence: `realtime.py`)
- Face Detector → Caffe Detector Weights: loads weights (evidence: `realtime.py`)
- YOLO Frame Processing → YOLO Model: runs inference (evidence: `realtime.py`)
- ResNet Prediction → ResNet-18 Weights: loads when selected (evidence: `realtime.py`)
- ResNet Prediction → ResNet-50 Weights: loads when selected (evidence: `realtime.py`)
- Ensemble Voting → ResNet Prediction: collects predictions (evidence: `realtime.py`)
- Ensemble Voting → YOLO Frame Processing: uses YOLO prediction (evidence: `realtime.py`)
- Interactive Menu → Result Display: shows image result (evidence: `realtime.py`)
- Webcam Loop → Result Display: displays frames (evidence: `realtime.py`)
