# chandrikadeb7/face-mask-detection architecture

> Architecture diagram of the GitHub repository chandrikadeb7/face-mask-detection, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/chandrikadeb7/face-mask-detection
- Repository: https://github.com/chandrikadeb7/face-mask-detection

## Overview

##### Project Type & Purpose
- This is a machine-learning‐powered computer vision system for face-mask detection. It includes:
- A training pipeline (TensorFlow/Keras + transfer learning on MobileNetV2, ResNet50_v2, InceptionV3)
- An inference/detection pipeline (OpenCV+Caffe face detector + mask‐vs‐no‐mask classifier)
- A simple web interface served via Streamlit (`app.py`)
- Utility scripts for dataset creation (`search.py`), model conversion (`model2onnx.py`), and Raspberry Pi/IoT setup

##### File Structure Analysis
TOP-LEVEL
- dataset/with_mask & dataset/without_mask – raw images
- face_detector/ – Caffe prototxt + weights for face detection
- incep_v3_mask_model/ + ResNet50_v2/ – Jupyter notebooks & helper scripts for alternative training runs
- train_mask_detector.py – main CLI training entrypoint
- detect_mask_image.py / detect_mask_video.py – standalone inference scripts
- model2onnx.py – converts the `.model` to ONNX for cross‐platform serving
- mask_detector.model – serialized Keras/TensorFlow classifier
- app.py + css/ – Streamlit webapp for real-time detection in browser
- requirements.txt – declared dependencies (OpenCV, TensorFlow, Keras, Streamlit, etc.)

##### README Insights
- Confirms use of MobileNetV2 (transfer learning), TensorFlow‐GPU, OpenCV DNN
- Demonstrates CLI usage, Python scripts for training/inference, and webapp commands
- Includes IoT section for Raspberry Pi deployment

##### Diagramming the Architecture
1. Data Store
– dataset/with_mask, dataset/without_mask
2. Training Pipeline
– `train_mask_detector.py`
– Helper notebooks (`incep_v3_mask_model/`, `ResNet50_v2/`)
– Outputs: `mask_detector.model` (and ONNX via `model2onnx.py`)
3. Face‐Detector Submodule
– Caffe model in face_detector/ (deploy.prototxt + .caffemodel)
4. Inference Pipelines
– CLI scripts (`detect_mask_image.py`, `detect_mask_video.py`)
– Streamlit Webapp (`app.py` + css/)
5. External/Edge Deployment
– Raspberry Pi + PiCamera (per README IoT section)
6. External Services & Clients
– Browser (Streamlit UI)
– DevOps: (Heroku/Gumroad links for demo/deployment)
- Raw Images → Training Pipeline → Trained Model (.model / .onnx)
- Trained Model + Face-Detector Caffe Model → Inference Engine
- Inference Engine → CLI Output / Streamlit Frontend → End User Display
- (Optional) Trained Model + Inference Engine → Raspberry Pi for Edge Deployment
c. Architectural Patterns & Principles
- Modular separation: data, training, model conversion, inference, UI
- Pipeline pattern for training vs. inference stages
- Single‐page interactive webapp (Streamlit) vs. standalone CLI tools
- Reusability: face detector and classifier are independent modules
d. Key Technologies & Frameworks
- Python 3.6+, OpenCV DNN (Caffe), TensorFlow/Keras, MobileNetV2, ONNX
- Streamlit for web UI
- Virtualenv / requirements.txt for environment management
- (Optional) Raspberry Pi dependencies for edge deployment

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Data & Models"
        direction TB
        DS1["With Mask Dataset"]:::data
        DS2["Without Mask Dataset"]:::data
        MODEL["mask_detector.model"]:::data
    end

    subgraph "Training Pipeline"
        direction TB
        TM["train_mask_detector.py"]:::compute
        IN1["incep_v3_mask_model/"]:::compute
        IN2["ResNet50_v2/"]:::compute
        MC["model2onnx.py"]:::compute
        SEARCH["search.py"]:::compute
    end

    subgraph "Inference Pipeline"
        direction TB
        FD["face_detector (Caffe Model)"]:::compute
        IM["detect_mask_image.py"]:::compute
        VID["detect_mask_video.py"]:::compute
    end

    subgraph "UI & Edge"
        direction TB
        APP["app.py (Streamlit UI)"]:::ui
        CSS["css/styles.css"]:::ui
        BROWSER["Browser"]:::ui
        PI["Raspberry Pi + PiCamera"]:::ui
    end

    %% Data to Training
    DS1 -->|"raw images"| TM
    DS2 -->|"raw images"| TM
    SEARCH -->|"collects images"| DS1
    SEARCH -->|"collects images"| DS2

    %% Training Flow
    TM -->|"outputs model"| MODEL
    TM -->|"uses notebooks"| IN1
    TM -->|"uses scripts"| IN2
    MODEL -->|"convert to ONNX"| MC

    %% Inference Flow
    FD -->|"detect faces"| IM
    MODEL -->|"classify masks"| IM
    FD -->|"detect faces"| VID
    MODEL -->|"classify masks"| VID

    %% UI Flow
    APP -->|"serves UI"| BROWSER
    APP -->|"uses face detector & model"| FD
    APP -->|"uses face detector & model"| MODEL
    APP -->|"loads styles"| CSS

    %% Edge Deployment
    MODEL -.->|"deploy model"| PI
    FD -.->|"deploy face detector"| PI

    %% Styles
    classDef data fill:#ADD8E6,stroke:#0000FF
    classDef compute fill:#90EE90,stroke:#008000
    classDef ui fill:#FFD580,stroke:#FF8C00

    %% Click Events
    click DS1 "https://github.com/chandrikadeb7/face-mask-detection/tree/master/dataset/with_mask"
    click DS2 "https://github.com/chandrikadeb7/face-mask-detection/tree/master/dataset/without_mask"
    click TM "https://github.com/chandrikadeb7/face-mask-detection/blob/master/train_mask_detector.py"
    click IN1 "https://github.com/chandrikadeb7/face-mask-detection/tree/master/incep_v3_mask_model/"
    click IN2 "https://github.com/chandrikadeb7/face-mask-detection/tree/master/ResNet50_v2/"
    click MODEL "https://github.com/chandrikadeb7/face-mask-detection/blob/master/mask_detector.model"
    click MC "https://github.com/chandrikadeb7/face-mask-detection/blob/master/model2onnx.py"
    click FD "https://github.com/chandrikadeb7/face-mask-detection/blob/master/face_detector/deploy.prototxt"
    click IM "https://github.com/chandrikadeb7/face-mask-detection/blob/master/detect_mask_image.py"
    click VID "https://github.com/chandrikadeb7/face-mask-detection/blob/master/detect_mask_video.py"
    click APP "https://github.com/chandrikadeb7/face-mask-detection/blob/master/app.py"
    click CSS "https://github.com/chandrikadeb7/face-mask-detection/blob/master/css/styles.css"
    click SEARCH "https://github.com/chandrikadeb7/face-mask-detection/blob/master/search.py"
```
