# vishl9455/facemask_detector architecture

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

- Interactive diagram: https://gitdiagram.com/vishl9455/facemask_detector
- Repository: https://github.com/vishl9455/facemask_detector

## Overview

This repository provides face-mask detection through a FastAPI image-upload interface and a separate OpenCV webcam program. Both detect faces with YOLO, preprocess each face, and classify it with a VGG16-based mask model. The training notebook is a separate model-development path. The API and webcam workflows are visible in sampled source; training details and frontend behavior are based on the README because those files were not sampled.

Main entry points: [`app.py`](https://github.com/vishl9455/facemask_detector/blob/main/app.py) (Prediction API), [`webcam.py`](https://github.com/vishl9455/facemask_detector/blob/main/webcam.py) (Webcam Detection), [`model.keras`](https://github.com/vishl9455/facemask_detector/blob/main/model.keras) (Classifier Model), [`static/index.html`](https://github.com/vishl9455/facemask_detector/blob/main/static/index.html) (Web Frontend)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["Web Interface"]
  node_browser["Browser"]
  node_frontend["Web Frontend<br/>[index.html]"]
  node_api["Prediction API<br/>[app.py]"]
end

subgraph group_inference["Detection and Classification"]
  node_image_decode["Image Decode<br/>[app.py]"]
  node_face_detector["YOLO Face Detector<br/>[app.py]"]
  node_face_crop["Face Crop<br/>[app.py]"]
  node_preprocess["Resize and Normalize<br/>[app.py]"]
  node_classifier["Mask Classifier<br/>[app.py]"]
  node_prediction_result["Mask Result<br/>[app.py]"]
  node_keras_model["Classifier Model<br/>[model.keras]"]
  node_yolo_model["YOLO Model<br/>[model.pt]"]
  node_webcam_runtime["Webcam Detection<br/>[webcam.py]"]
  node_display["Annotated Video<br/>[webcam.py]"]
end

subgraph group_training["Model Training"]
  node_training["Classifier Training<br/>[train_model.ipynb]"]
end

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

node_user -->|"uses"| node_browser
node_browser -->|"loads"| node_frontend
node_frontend -.->|"uploads image"| node_api
node_api -->|"decodes upload"| node_image_decode
node_image_decode -->|"detects faces"| node_face_detector
node_face_detector -->|"provides boxes"| node_face_crop
node_face_crop -->|"crops faces"| node_preprocess
node_preprocess -->|"prepares input"| node_classifier
node_classifier -->|"labels prediction"| node_prediction_result
node_api -->|"loads"| node_keras_model
node_api -->|"loads"| node_yolo_model
node_camera -->|"streams frames"| node_webcam_runtime
node_webcam_runtime -->|"detects faces"| node_yolo_model
node_webcam_runtime -->|"classifies crops"| node_keras_model
node_webcam_runtime -->|"annotates frames"| node_display
node_training -.->|"trains and saves"| node_keras_model

click node_frontend "https://github.com/vishl9455/facemask_detector/blob/main/static/index.html"
click node_api "https://github.com/vishl9455/facemask_detector/blob/main/app.py"
click node_image_decode "https://github.com/vishl9455/facemask_detector/blob/main/app.py"
click node_face_detector "https://github.com/vishl9455/facemask_detector/blob/main/app.py"
click node_face_crop "https://github.com/vishl9455/facemask_detector/blob/main/app.py"
click node_preprocess "https://github.com/vishl9455/facemask_detector/blob/main/app.py"
click node_classifier "https://github.com/vishl9455/facemask_detector/blob/main/app.py"
click node_prediction_result "https://github.com/vishl9455/facemask_detector/blob/main/app.py"
click node_keras_model "https://github.com/vishl9455/facemask_detector/blob/main/model.keras"
click node_yolo_model "https://github.com/vishl9455/facemask_detector/blob/main/model.pt"
click node_webcam_runtime "https://github.com/vishl9455/facemask_detector/blob/main/webcam.py"
click node_display "https://github.com/vishl9455/facemask_detector/blob/main/webcam.py"
click node_training "https://github.com/vishl9455/facemask_detector/blob/main/train_model.ipynb"

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_browser,node_frontend,node_api,node_user toneBlue
class node_image_decode,node_face_detector,node_face_crop,node_preprocess,node_classifier,node_prediction_result,node_keras_model,node_yolo_model,node_webcam_runtime,node_display toneAmber
class node_training toneMint
class node_camera toneIndigo
```

## Components

### Web Interface

- **Browser**
- [Web Frontend](https://github.com/vishl9455/facemask_detector/blob/main/static/index.html): `static/index.html`
- [Prediction API](https://github.com/vishl9455/facemask_detector/blob/main/app.py): `app.py`

### Detection and Classification

- [Image Decode](https://github.com/vishl9455/facemask_detector/blob/main/app.py): `app.py`
- [YOLO Face Detector](https://github.com/vishl9455/facemask_detector/blob/main/app.py): `app.py`
- [Face Crop](https://github.com/vishl9455/facemask_detector/blob/main/app.py): `app.py`
- [Resize and Normalize](https://github.com/vishl9455/facemask_detector/blob/main/app.py): `app.py`
- [Mask Classifier](https://github.com/vishl9455/facemask_detector/blob/main/app.py): `app.py`
- [Mask Result](https://github.com/vishl9455/facemask_detector/blob/main/app.py): `app.py`
- [Classifier Model](https://github.com/vishl9455/facemask_detector/blob/main/model.keras): `model.keras`
- [YOLO Model](https://github.com/vishl9455/facemask_detector/blob/main/model.pt): `model.pt`
- [Webcam Detection](https://github.com/vishl9455/facemask_detector/blob/main/webcam.py): `webcam.py`
- [Annotated Video](https://github.com/vishl9455/facemask_detector/blob/main/webcam.py): `webcam.py`

### Model Training

- [Classifier Training](https://github.com/vishl9455/facemask_detector/blob/main/train_model.ipynb): `train_model.ipynb`

### Other components

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

## Connections

- User → Browser: uses
- Browser → Web Frontend: loads
- Web Frontend → Prediction API: uploads image
- Prediction API → Image Decode: decodes upload (evidence: `app.py`)
- Image Decode → YOLO Face Detector: detects faces (evidence: `app.py`)
- YOLO Face Detector → Face Crop: provides boxes (evidence: `app.py`)
- Face Crop → Resize and Normalize: crops faces (evidence: `app.py`)
- Resize and Normalize → Mask Classifier: prepares input (evidence: `app.py`)
- Mask Classifier → Mask Result: labels prediction (evidence: `app.py`)
- Prediction API → Classifier Model: loads (evidence: `app.py`)
- Prediction API → YOLO Model: loads (evidence: `app.py`)
- Webcam → Webcam Detection: streams frames (evidence: `webcam.py`)
- Webcam Detection → YOLO Model: detects faces (evidence: `webcam.py`)
- Webcam Detection → Classifier Model: classifies crops (evidence: `webcam.py`)
- Webcam Detection → Annotated Video: annotates frames (evidence: `webcam.py`)
- Classifier Training → Classifier Model: trains and saves (evidence: `README.md`)
