# trahulsingh/deepfakedetector architecture

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

- Interactive diagram: https://gitdiagram.com/trahulsingh/deepfakedetector
- Repository: https://github.com/trahulsingh/deepfakedetector

## Overview

The repository is a deepfake image/video classifier built around an EfficientNet-B0 model. Its main user workflow is uploading an image or video to the Gradio app, which preprocesses it, predicts real versus deepfake, and returns a confidence and preview. Separate entry points provide command-line image classification, first-frame web analysis, and multi-frame folder-based video inference. The training workflow loads labeled image datasets, trains and validates the detector, and supports checkpoint conversion and ONNX export. The README documents capabilities whose implementation was not sampled; those are represented only where paths or relationships are supported.

Main entry points: [`main_trainer.py`](https://github.com/trahulsingh/deepfakedetector/blob/main/main_trainer.py) (Training Orchestrator), [`web-app.py`](https://github.com/trahulsingh/deepfakedetector/blob/main/web-app.py) (Image/Video Prediction), [`tools/export_to_pt.py`](https://github.com/trahulsingh/deepfakedetector/blob/main/tools/export_to_pt.py) (PyTorch Checkpoint Export), [`lightning_modules/detector.py`](https://github.com/trahulsingh/deepfakedetector/blob/main/lightning_modules/detector.py) (Lightning Detector)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_detection["Detection"]
  node_webui["Gradio Interface<br/>[web-app.py]"]
  node_webpredict["Image/Video Prediction<br/>[web-app.py]"]
  node_weights["Trained Weights<br/>[best_model-v3.pt]"]
  node_cli["Image Classification<br/>[classify.py]"]
  node_video["Multi-frame Inference<br/>[video_inference.py]"]
  node_realeval["Real-world Evaluation<br/>[realeval.py]"]
end

subgraph group_training["Training"]
  node_config["Training Config<br/>[config.yaml]"]
  node_trainentry["Training Orchestrator<br/>[main_trainer.py]"]
  node_dataset["Hybrid Dataset Loader<br/>[hybrid_loader.py]"]
  node_detector["Lightning Detector<br/>[detector.py]"]
end

subgraph group_preparation["Dataset Preparation"]
  node_video_split["Video Dataset Splitter"]
  node_image_split["Image Train/Val Splitter<br/>[split_train_val.py]"]
  node_frame_extract["Video Frame Extractor<br/>[split_dataset.py]"]
end

subgraph group_export["Model Export"]
  node_pt_export["PyTorch Checkpoint Export<br/>[export_to_pt.py]"]
  node_onnx_export["ONNX Export<br/>[export_onnx.py]"]
end

node_user(("User"))

node_user -->|"uploads media"| node_webui
node_webui -->|"dispatches input"| node_webpredict
node_webpredict -->|"loads weights"| node_weights
node_webpredict -->|"returns prediction"| node_user
node_user -->|"classifies image"| node_cli
node_user -->|"runs folder analysis"| node_video
node_user -.->|"evaluates samples"| node_realeval
node_trainentry -->|"reads settings"| node_config
node_trainentry -->|"builds datasets"| node_dataset
node_trainentry -->|"constructs detector"| node_detector
node_user -->|"prepares videos"| node_video_split
node_user -->|"splits images"| node_image_split
node_user -->|"extracts frames"| node_frame_extract
node_user -.->|"converts checkpoint"| node_pt_export
node_user -->|"exports model"| node_onnx_export
node_pt_export -->|"loads checkpoint class"| node_detector

click node_webui "https://github.com/trahulsingh/deepfakedetector/blob/main/web-app.py"
click node_webpredict "https://github.com/trahulsingh/deepfakedetector/blob/main/web-app.py"
click node_weights "https://github.com/trahulsingh/deepfakedetector/blob/main/models/best_model-v3.pt"
click node_cli "https://github.com/trahulsingh/deepfakedetector/blob/main/classify.py"
click node_video "https://github.com/trahulsingh/deepfakedetector/blob/main/inference/video_inference.py"
click node_realeval "https://github.com/trahulsingh/deepfakedetector/blob/main/realeval.py"
click node_config "https://github.com/trahulsingh/deepfakedetector/blob/main/config.yaml"
click node_trainentry "https://github.com/trahulsingh/deepfakedetector/blob/main/main_trainer.py"
click node_dataset "https://github.com/trahulsingh/deepfakedetector/blob/main/datasets/hybrid_loader.py"
click node_detector "https://github.com/trahulsingh/deepfakedetector/blob/main/lightning_modules/detector.py"
click node_video_split "https://github.com/trahulsingh/deepfakedetector/blob/main/tools/split_video_dataset.py"
click node_image_split "https://github.com/trahulsingh/deepfakedetector/blob/main/tools/split_train_val.py"
click node_frame_extract "https://github.com/trahulsingh/deepfakedetector/blob/main/tools/split_dataset.py"
click node_pt_export "https://github.com/trahulsingh/deepfakedetector/blob/main/tools/export_to_pt.py"
click node_onnx_export "https://github.com/trahulsingh/deepfakedetector/blob/main/inference/export_onnx.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_webui,node_webpredict,node_weights,node_cli,node_video,node_realeval,node_user toneBlue
class node_config,node_trainentry,node_dataset,node_detector toneAmber
class node_video_split,node_image_split,node_frame_extract toneMint
class node_pt_export,node_onnx_export toneRose
```

## Components

### Detection

- [Gradio Interface](https://github.com/trahulsingh/deepfakedetector/blob/main/web-app.py): `web-app.py`
- [Image/Video Prediction](https://github.com/trahulsingh/deepfakedetector/blob/main/web-app.py): `web-app.py`
- [Trained Weights](https://github.com/trahulsingh/deepfakedetector/blob/main/models/best_model-v3.pt): `models/best_model-v3.pt`
- [Image Classification](https://github.com/trahulsingh/deepfakedetector/blob/main/classify.py): `classify.py`
- [Multi-frame Inference](https://github.com/trahulsingh/deepfakedetector/blob/main/inference/video_inference.py): `inference/video_inference.py`
- [Real-world Evaluation](https://github.com/trahulsingh/deepfakedetector/blob/main/realeval.py): `realeval.py`

### Training

- [Training Config](https://github.com/trahulsingh/deepfakedetector/blob/main/config.yaml): `config.yaml`
- [Training Orchestrator](https://github.com/trahulsingh/deepfakedetector/blob/main/main_trainer.py): `main_trainer.py`
- [Hybrid Dataset Loader](https://github.com/trahulsingh/deepfakedetector/blob/main/datasets/hybrid_loader.py): `datasets/hybrid_loader.py`
- [Lightning Detector](https://github.com/trahulsingh/deepfakedetector/blob/main/lightning_modules/detector.py): `lightning_modules/detector.py`

### Dataset Preparation

- [Video Dataset Splitter](https://github.com/trahulsingh/deepfakedetector/blob/main/tools/split_video_dataset.py): `tools/split_video_dataset.py`
- [Image Train/Val Splitter](https://github.com/trahulsingh/deepfakedetector/blob/main/tools/split_train_val.py): `tools/split_train_val.py`
- [Video Frame Extractor](https://github.com/trahulsingh/deepfakedetector/blob/main/tools/split_dataset.py): `tools/split_dataset.py`

### Model Export

- [PyTorch Checkpoint Export](https://github.com/trahulsingh/deepfakedetector/blob/main/tools/export_to_pt.py): `tools/export_to_pt.py`
- [ONNX Export](https://github.com/trahulsingh/deepfakedetector/blob/main/inference/export_onnx.py): `inference/export_onnx.py`

### Other components

- **User**

## Connections

- User → Gradio Interface: uploads media (evidence: `README.md`)
- Gradio Interface → Image/Video Prediction: dispatches input (evidence: `web-app.py`)
- Image/Video Prediction → Trained Weights: loads weights (evidence: `web-app.py`)
- Image/Video Prediction → User: returns prediction (evidence: `web-app.py`)
- User → Image Classification: classifies image (evidence: `README.md`)
- User → Multi-frame Inference: runs folder analysis (evidence: `README.md`)
- User → Real-world Evaluation: evaluates samples
- Training Orchestrator → Training Config: reads settings (evidence: `main_trainer.py`)
- Training Orchestrator → Hybrid Dataset Loader: builds datasets (evidence: `main_trainer.py`)
- Training Orchestrator → Lightning Detector: constructs detector (evidence: `main_trainer.py`)
- User → Video Dataset Splitter: prepares videos (evidence: `README.md`)
- User → Image Train/Val Splitter: splits images (evidence: `README.md`)
- User → Video Frame Extractor: extracts frames (evidence: `README.md`)
- User → PyTorch Checkpoint Export: converts checkpoint
- User → ONNX Export: exports model (evidence: `README.md`)
- PyTorch Checkpoint Export → Lightning Detector: loads checkpoint class (evidence: `tools/export_to_pt.py`)
