# under-the-horizon/deepfake_detection architecture

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

- Interactive diagram: https://gitdiagram.com/under-the-horizon/deepfake_detection
- Repository: https://github.com/under-the-horizon/deepfake_detection

## Overview

Deepfake_Detection trains a frame-based real/fake classifier and provides both command-line and Gradio video inference, plus benchmark evaluation. Inference samples and preprocesses frames, runs the detector, averages class probabilities, and reports a verdict. Training builds Celeb-DF frame batches, combines classification and contrastive losses, and saves the best weights. The README describes broader hybrid-model capabilities; sampled implementation shows a CNN feature extractor, spatial Transformer, and Conv1D head, but not a separate Siamese or Swin implementation. Edges reflect explicit calls and documented behavior in the excerpts.

Main entry points: [`models/detector.py`](https://github.com/under-the-horizon/deepfake_detection/blob/main/models/detector.py) (Detector orchestrator), [`train.py`](https://github.com/under-the-horizon/deepfake_detection/blob/main/train.py) (Training loop), [`infer.py`](https://github.com/under-the-horizon/deepfake_detection/blob/main/infer.py) (CLI inference), [`evaluate.py`](https://github.com/under-the-horizon/deepfake_detection/blob/main/evaluate.py) (Evaluation run)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_training["Training Data &amp; Learning"]
  node_dataset["Celeb-DF dataset<br/>[dataset.py]"]
  node_config["Run configuration<br/>[config.py]"]
  node_train["Training loop<br/>[train.py]"]
  node_contrastive["Contrastive loss<br/>[contrastive.py]"]
  node_weights[("Saved detector weights<br/>[config.py]")]
end

subgraph group_model["Detection Model"]
  node_detector["Detector orchestrator<br/>[detector.py]"]
  node_extractor["CNN feature extractor<br/>[components.py]"]
  node_transformer["Spatial Transformer<br/>[components.py]"]
  node_head["Conv1D classifier<br/>[components.py]"]
end

subgraph group_inference["Video Inference"]
  node_cli["CLI inference<br/>[infer.py]"]
  node_web["Gradio interface<br/>[app.py]"]
  node_frameprep["Frame sampling &amp; prep<br/>[infer.py]"]
  node_webprep["Web frame prep<br/>[app.py]"]
  node_verdict["Video verdict<br/>[infer.py]"]
  node_webresult["Web result<br/>[app.py]"]
end

subgraph group_assessment["Model Assessment"]
  node_evaluator["Evaluation run<br/>[evaluate.py]"]
  node_metrics["Classification metrics<br/>[evaluate.py]"]
end

node_user(("Video user"))
node_trainer(("Training run"))

node_trainer -->|"starts"| node_train
node_train -->|"reads"| node_config
node_train -->|"loads batches"| node_dataset
node_train -->|"trains"| node_detector
node_train -->|"computes loss"| node_contrastive
node_train -->|"saves best"| node_weights
node_detector -->|"calls"| node_extractor
node_detector -->|"calls"| node_transformer
node_detector -->|"calls"| node_head
node_user -->|"uploads video"| node_web
node_web -->|"preprocesses"| node_webprep
node_web -->|"classifies frames"| node_detector
node_web -->|"returns verdict"| node_webresult
node_trainer -->|"runs inference"| node_cli
node_cli -->|"reads"| node_config
node_cli -->|"loads"| node_weights
node_cli -->|"extracts frames"| node_frameprep
node_cli -->|"classifies frames"| node_detector
node_cli -->|"averages probabilities"| node_verdict
node_trainer -->|"runs evaluation"| node_evaluator
node_evaluator -->|"reads"| node_config
node_evaluator -->|"loads"| node_weights
node_evaluator -->|"loads test data"| node_dataset
node_evaluator -->|"evaluates"| node_detector
node_evaluator -->|"computes"| node_metrics

click node_dataset "https://github.com/under-the-horizon/deepfake_detection/blob/main/data/dataset.py"
click node_config "https://github.com/under-the-horizon/deepfake_detection/blob/main/configs/config.py"
click node_train "https://github.com/under-the-horizon/deepfake_detection/blob/main/train.py"
click node_contrastive "https://github.com/under-the-horizon/deepfake_detection/blob/main/losses/contrastive.py"
click node_weights "https://github.com/under-the-horizon/deepfake_detection/blob/main/configs/config.py"
click node_detector "https://github.com/under-the-horizon/deepfake_detection/blob/main/models/detector.py"
click node_extractor "https://github.com/under-the-horizon/deepfake_detection/blob/main/models/components.py"
click node_transformer "https://github.com/under-the-horizon/deepfake_detection/blob/main/models/components.py"
click node_head "https://github.com/under-the-horizon/deepfake_detection/blob/main/models/components.py"
click node_cli "https://github.com/under-the-horizon/deepfake_detection/blob/main/infer.py"
click node_web "https://github.com/under-the-horizon/deepfake_detection/blob/main/app.py"
click node_frameprep "https://github.com/under-the-horizon/deepfake_detection/blob/main/infer.py"
click node_webprep "https://github.com/under-the-horizon/deepfake_detection/blob/main/app.py"
click node_verdict "https://github.com/under-the-horizon/deepfake_detection/blob/main/infer.py"
click node_webresult "https://github.com/under-the-horizon/deepfake_detection/blob/main/app.py"
click node_evaluator "https://github.com/under-the-horizon/deepfake_detection/blob/main/evaluate.py"
click node_metrics "https://github.com/under-the-horizon/deepfake_detection/blob/main/evaluate.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_dataset,node_config,node_train,node_contrastive,node_weights,node_user toneBlue
class node_detector,node_extractor,node_transformer,node_head toneAmber
class node_cli,node_web,node_frameprep,node_webprep,node_verdict,node_webresult toneMint
class node_evaluator,node_metrics toneRose
class node_trainer toneIndigo
```

## Components

### Training Data & Learning

- [Celeb-DF dataset](https://github.com/under-the-horizon/deepfake_detection/blob/main/data/dataset.py): `data/dataset.py`
- [Run configuration](https://github.com/under-the-horizon/deepfake_detection/blob/main/configs/config.py): `configs/config.py`
- [Training loop](https://github.com/under-the-horizon/deepfake_detection/blob/main/train.py): `train.py`
- [Contrastive loss](https://github.com/under-the-horizon/deepfake_detection/blob/main/losses/contrastive.py): `losses/contrastive.py`
- [Saved detector weights](https://github.com/under-the-horizon/deepfake_detection/blob/main/configs/config.py): `configs/config.py`

### Detection Model

- [Detector orchestrator](https://github.com/under-the-horizon/deepfake_detection/blob/main/models/detector.py): `models/detector.py`
- [CNN feature extractor](https://github.com/under-the-horizon/deepfake_detection/blob/main/models/components.py): `models/components.py`
- [Spatial Transformer](https://github.com/under-the-horizon/deepfake_detection/blob/main/models/components.py): `models/components.py`
- [Conv1D classifier](https://github.com/under-the-horizon/deepfake_detection/blob/main/models/components.py): `models/components.py`

### Video Inference

- [CLI inference](https://github.com/under-the-horizon/deepfake_detection/blob/main/infer.py): `infer.py`
- [Gradio interface](https://github.com/under-the-horizon/deepfake_detection/blob/main/app.py): `app.py`
- [Frame sampling & prep](https://github.com/under-the-horizon/deepfake_detection/blob/main/infer.py): `infer.py`
- [Web frame prep](https://github.com/under-the-horizon/deepfake_detection/blob/main/app.py): `app.py`
- [Video verdict](https://github.com/under-the-horizon/deepfake_detection/blob/main/infer.py): `infer.py`
- [Web result](https://github.com/under-the-horizon/deepfake_detection/blob/main/app.py): `app.py`

### Model Assessment

- [Evaluation run](https://github.com/under-the-horizon/deepfake_detection/blob/main/evaluate.py): `evaluate.py`
- [Classification metrics](https://github.com/under-the-horizon/deepfake_detection/blob/main/evaluate.py): `evaluate.py`

### Other components

- **Video user**
- **Training run**

## Connections

- Training run → Training loop: starts (evidence: `train.py`)
- Training loop → Run configuration: reads (evidence: `train.py`)
- Training loop → Celeb-DF dataset: loads batches (evidence: `train.py`)
- Training loop → Detector orchestrator: trains (evidence: `train.py`)
- Training loop → Contrastive loss: computes loss (evidence: `train.py`)
- Training loop → Saved detector weights: saves best (evidence: `train.py`)
- Detector orchestrator → CNN feature extractor: calls (evidence: `models/detector.py`)
- Detector orchestrator → Spatial Transformer: calls (evidence: `models/detector.py`)
- Detector orchestrator → Conv1D classifier: calls (evidence: `models/detector.py`)
- Video user → Gradio interface: uploads video (evidence: `app.py`)
- Gradio interface → Web frame prep: preprocesses (evidence: `app.py`)
- Gradio interface → Detector orchestrator: classifies frames (evidence: `app.py`)
- Gradio interface → Web result: returns verdict (evidence: `app.py`)
- Training run → CLI inference: runs inference (evidence: `infer.py`)
- CLI inference → Run configuration: reads (evidence: `infer.py`)
- CLI inference → Saved detector weights: loads (evidence: `infer.py`)
- CLI inference → Frame sampling & prep: extracts frames (evidence: `infer.py`)
- CLI inference → Detector orchestrator: classifies frames (evidence: `infer.py`)
- CLI inference → Video verdict: averages probabilities (evidence: `infer.py`)
- Training run → Evaluation run: runs evaluation (evidence: `evaluate.py`)
- Evaluation run → Run configuration: reads (evidence: `evaluate.py`)
- Evaluation run → Saved detector weights: loads (evidence: `evaluate.py`)
- Evaluation run → Celeb-DF dataset: loads test data (evidence: `evaluate.py`)
- Evaluation run → Detector orchestrator: evaluates (evidence: `evaluate.py`)
- Evaluation run → Classification metrics: computes (evidence: `evaluate.py`)
