# sufi2911/deeplearning_project architecture

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

- Interactive diagram: https://gitdiagram.com/sufi2911/deeplearning_project
- Repository: https://github.com/sufi2911/deeplearning_project

## Overview

#### Purpose and Entry Points
This is a local, CPU-oriented deepfake face classifier plus live interview-proctoring application. The primary runtime entry point is the Streamlit UI in `app.py`. ML lifecycle commands run as Python scripts: `src/train.py` trains, `src/evaluate.py` evaluates, and `src/check_data.py` validates dataset balance.

#### Streamlit Application and User Flows
`app.py` hosts three interaction modes: uploaded-image classification, a single webcam snapshot, and continuous live webcam detection. Still-image and snapshot flows pass an image to inference and present Real/Fake confidence, Grad-CAM output, and face-attention status. Live mode continuously combines deepfake prediction with proctoring events and applies a three-second escalation grace period through application state.
- `app.py`
- `components/browser_monitor/index.html`

#### Deepfake Model Boundary
The classifier is a transfer-learned EfficientNet-B0 with a binary classifier head (fake is positive). Model construction is isolated from UI and training/inference orchestration in `src/model.py`. A persisted checkpoint contains learned weights and a validation-selected decision threshold, making `models/best_model.pth` the contract between training and serving.
- `src/model.py`
- `models/best_model.pth`

#### Image Inference and Explainability
Inference loads the checkpoint, prepares images, detects/crops a face with OpenCV (or uses the full image as fallback), scores the image, and creates Grad-CAM explanations. This is the central reusable service layer for both Streamlit and direct Python consumers. It also contains attention-analysis thresholds and APIs used by proctoring.
- `src/inference.py`
- `src/utils.py`
- `app.py`

#### Live Proctoring Pipeline
Live webcam frames are analyzed with MediaPipe Face Landmarker for face count, eye openness, iris-based gaze direction, and head pose. The app turns these transient observations into sustained violation state; multiple faces, closed eyes, looking away, head turns, browser focus loss, and audio anomalies may become cheating signals after the grace window. Browser events originate in a separate browser-side component rather than server vision processing.
- `app.py`
- `src/inference.py`
- `components/browser_monitor/index.html`

#### Training, Validation, and Evaluation
Training consumes labeled real/fake image directories, with alternate `real_image`/`fake_image` names supported. It trains primarily the classifier and optionally final backbone blocks, uses validation loss for early stopping, tunes the operating threshold on validation data, and writes the best checkpoint. Evaluation consumes the labeled test split and emits a classification report and confusion-matrix artifact.
- `src/train.py`
- `src/evaluate.py`
- `dataset/train/image_labels.csv`
- `dataset/val/image_labels.csv`
- `dataset/test/image_labels.csv`
- `models/evaluation/classification_report.txt`

#### Runtime, Storage, and External Dependencies
The stack is Python/Streamlit, PyTorch/timm EfficientNet, OpenCV, and MediaPipe; no database, cloud backend, or paid API is represented. Training may download ImageNet-pretrained EfficientNet weights through `timm`; first webcam use downloads the MediaPipe task model into `models/`. Camera capture is browser-mediated and therefore requires localhost or HTTPS. The dataset and checkpoint are local filesystem artifacts.
- `requirements.txt`
- `models/best_model.pth`
- `dataset/train/fake_image`
- `dataset/train/real_image`

Main entry points: [`src/inference.py`](https://github.com/sufi2911/deeplearning_project/blob/main/src/inference.py) (Inference & Grad-CAM), [`app.py`](https://github.com/sufi2911/deeplearning_project/blob/main/app.py) (Streamlit app), [`src/train.py`](https://github.com/sufi2911/deeplearning_project/blob/main/src/train.py) (Training), [`models/best_model.pth`](https://github.com/sufi2911/deeplearning_project/blob/main/models/best_model.pth) (Best model checkpoint)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["Interactive Proctoring"]
  node_app["Streamlit app<br/>Python UI<br/>[app.py]"]
  node_browser_monitor["Browser monitor<br/>browser component<br/>[index.html]"]
  node_live_state(("Violation state<br/>application state<br/>[app.py]"))
end

subgraph group_serving["Inference Services"]
  node_model["EfficientNet-B0 classifier<br/>model definition<br/>[model.py]"]
  node_inference["Inference &amp; Grad-CAM<br/>Python service<br/>[inference.py]"]
  node_vision_utils["Image utilities<br/>vision utility<br/>[utils.py]"]
  node_face_landmarker["Face &amp; behavior analysis<br/>MediaPipe pipeline"]
end

subgraph group_ml["ML Lifecycle"]
  node_train["Training<br/>Python command<br/>[train.py]"]
  node_data_check["Dataset validation<br/>Python command<br/>[check_data.py]"]
  node_evaluate["Evaluation<br/>Python command<br/>[evaluate.py]"]
end

subgraph group_local["Local Artifacts"]
  node_train_labels["Training labels<br/>CSV split<br/>[image_labels.csv]"]
  node_train_images["Training images<br/>real/fake directories"]
  node_val_labels["Validation labels<br/>CSV split<br/>[image_labels.csv]"]
  node_test_labels["Test labels<br/>CSV split<br/>[image_labels.csv]"]
  node_checkpoint[("Best model checkpoint<br/>weights + threshold<br/>[best_model.pth]")]
  node_report["Classification report<br/>evaluation artifact"]
  node_dependencies["Runtime dependencies<br/>Python requirements<br/>[requirements.txt]"]
end

node_browser_monitor -->|"browser events"| node_app
node_app -->|"still frames"| node_inference
node_app -->|"live frames"| node_face_landmarker
node_inference -->|"prediction &amp; attention"| node_live_state
node_face_landmarker -->|"behavior observations"| node_live_state
node_browser_monitor -->|"focus/audio signals"| node_live_state
node_live_state -->|"sustained alerts"| node_app
node_inference -->|"constructs model"| node_model
node_inference -->|"image preparation"| node_vision_utils
node_checkpoint -->|"weights &amp; threshold"| node_inference
node_train_labels -->|"labels"| node_train
node_train_images -->|"images"| node_train
node_val_labels -->|"validation split"| node_train
node_model -->|"classifier architecture"| node_train
node_train -->|"writes best checkpoint"| node_checkpoint
node_train_labels -->|"validates balance"| node_data_check
node_checkpoint -->|"model to test"| node_evaluate
node_test_labels -->|"test split"| node_evaluate
node_evaluate -->|"writes metrics"| node_report
node_dependencies -.->|"runtime stack"| node_app

click node_app "https://github.com/sufi2911/deeplearning_project/blob/main/app.py"
click node_browser_monitor "https://github.com/sufi2911/deeplearning_project/blob/main/components/browser_monitor/index.html"
click node_live_state "https://github.com/sufi2911/deeplearning_project/blob/main/app.py"
click node_model "https://github.com/sufi2911/deeplearning_project/blob/main/src/model.py"
click node_inference "https://github.com/sufi2911/deeplearning_project/blob/main/src/inference.py"
click node_vision_utils "https://github.com/sufi2911/deeplearning_project/blob/main/src/utils.py"
click node_train "https://github.com/sufi2911/deeplearning_project/blob/main/src/train.py"
click node_data_check "https://github.com/sufi2911/deeplearning_project/blob/main/src/check_data.py"
click node_evaluate "https://github.com/sufi2911/deeplearning_project/blob/main/src/evaluate.py"
click node_train_labels "https://github.com/sufi2911/deeplearning_project/blob/main/dataset/train/image_labels.csv"
click node_train_images "https://github.com/sufi2911/deeplearning_project/tree/main/dataset/train/fake_image"
click node_val_labels "https://github.com/sufi2911/deeplearning_project/blob/main/dataset/val/image_labels.csv"
click node_test_labels "https://github.com/sufi2911/deeplearning_project/blob/main/dataset/test/image_labels.csv"
click node_checkpoint "https://github.com/sufi2911/deeplearning_project/blob/main/models/best_model.pth"
click node_report "https://github.com/sufi2911/deeplearning_project/blob/main/models/evaluation/classification_report.txt"
click node_dependencies "https://github.com/sufi2911/deeplearning_project/blob/main/requirements.txt"

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_app,node_browser_monitor,node_live_state toneBlue
class node_model,node_inference,node_vision_utils,node_face_landmarker toneAmber
class node_train,node_data_check,node_evaluate toneMint
class node_train_labels,node_train_images,node_val_labels,node_test_labels,node_checkpoint,node_report,node_dependencies toneRose
```

## Components

### Interactive Proctoring

- [Streamlit app](https://github.com/sufi2911/deeplearning_project/blob/main/app.py): Python UI · Hosts image, snapshot, and live webcam modes. · `app.py`
- [Browser monitor](https://github.com/sufi2911/deeplearning_project/blob/main/components/browser_monitor/index.html): browser component · Reports focus-loss and audio anomaly events. · `components/browser_monitor/index.html`
- [Violation state](https://github.com/sufi2911/deeplearning_project/blob/main/app.py): application state · Applies the three-second escalation grace period. · `app.py`

### Inference Services

- [EfficientNet-B0 classifier](https://github.com/sufi2911/deeplearning_project/blob/main/src/model.py): model definition · Transfer-learned binary fake-positive classifier. · `src/model.py`
- [Inference & Grad-CAM](https://github.com/sufi2911/deeplearning_project/blob/main/src/inference.py): Python service · Face crop, scoring, explanations, and attention APIs. · `src/inference.py`
- [Image utilities](https://github.com/sufi2911/deeplearning_project/blob/main/src/utils.py): vision utility · `src/utils.py`
- **Face & behavior analysis**: MediaPipe pipeline · Detects face count, eyes, gaze, and head pose from live frames.

### ML Lifecycle

- [Training](https://github.com/sufi2911/deeplearning_project/blob/main/src/train.py): Python command · Tunes threshold and writes the validation-selected checkpoint. · `src/train.py`
- [Dataset validation](https://github.com/sufi2911/deeplearning_project/blob/main/src/check_data.py): Python command · Checks labeled dataset balance. · `src/check_data.py`
- [Evaluation](https://github.com/sufi2911/deeplearning_project/blob/main/src/evaluate.py): Python command · Produces test metrics and confusion-matrix artifacts. · `src/evaluate.py`

### Local Artifacts

- [Training labels](https://github.com/sufi2911/deeplearning_project/blob/main/dataset/train/image_labels.csv): CSV split · `dataset/train/image_labels.csv`
- [Training images](https://github.com/sufi2911/deeplearning_project/tree/main/dataset/train/fake_image): real/fake directories · `dataset/train/fake_image`
- [Validation labels](https://github.com/sufi2911/deeplearning_project/blob/main/dataset/val/image_labels.csv): CSV split · `dataset/val/image_labels.csv`
- [Test labels](https://github.com/sufi2911/deeplearning_project/blob/main/dataset/test/image_labels.csv): CSV split · `dataset/test/image_labels.csv`
- [Best model checkpoint](https://github.com/sufi2911/deeplearning_project/blob/main/models/best_model.pth): weights + threshold · Serving contract containing learned weights and operating threshold. · `models/best_model.pth`
- [Classification report](https://github.com/sufi2911/deeplearning_project/blob/main/models/evaluation/classification_report.txt): evaluation artifact · `models/evaluation/classification_report.txt`
- [Runtime dependencies](https://github.com/sufi2911/deeplearning_project/blob/main/requirements.txt): Python requirements · PyTorch/timm, OpenCV, MediaPipe, and Streamlit. · `requirements.txt`

## Connections

- Browser monitor → Streamlit app: browser events
- Streamlit app → Inference & Grad-CAM: still frames
- Streamlit app → Face & behavior analysis: live frames
- Inference & Grad-CAM → Violation state: prediction & attention
- Face & behavior analysis → Violation state: behavior observations
- Browser monitor → Violation state: focus/audio signals
- Violation state → Streamlit app: sustained alerts
- Inference & Grad-CAM → EfficientNet-B0 classifier: constructs model
- Inference & Grad-CAM → Image utilities: image preparation
- Best model checkpoint → Inference & Grad-CAM: weights & threshold
- Training labels → Training: labels
- Training images → Training: images
- Validation labels → Training: validation split
- EfficientNet-B0 classifier → Training: classifier architecture
- Training → Best model checkpoint: writes best checkpoint
- Training labels → Dataset validation: validates balance
- Best model checkpoint → Evaluation: model to test
- Test labels → Evaluation: test split
- Evaluation → Classification report: writes metrics
- Runtime dependencies → Streamlit app: runtime stack
