# jeetpatil12/deepfake-detection architecture

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

- Interactive diagram: https://gitdiagram.com/jeetpatil12/deepfake-detection
- Repository: https://github.com/jeetpatil12/deepfake-detection

## Overview

##### Project Type and Purpose
– This is a data-driven, full-stack ML pipeline whose goal is to detect deepfakes in video data.
– Key activities: ingest video files, extract frames, label data, create balanced splits, sample data, train and fine-tune models, evaluate performance.

##### File Structure
Top-level scripts/notebooks reveal the stages:
– Data Preparation:
- images.py (frame extraction)
- videolabels.py (assign genuine vs. fake labels)
- split.py / split_balanced.py (train/val/test splits, balanced splits)
- weightsampler.py (class-biased sampling)
– Model Training & Tuning:
- train.py (base training loop)
- finetune.py (fine-tuning pre-trained weights)
- deepfake_lstm.ipynb, lightning.ipynb (experiment notebooks)
– Evaluation & Inference:
- script.py (likely inference / pipeline runner)
- train_balanced_multisource_deepfake.ipynb (multi-source experiments)
– Orchestrating Notebooks:
- deepfake.ipynb, train.ipynb (end-to-end demos)

##### README
– README only gives project title “Deepfake-Detection,” so infer pipeline stages from file names.

##### Main Components & Interactions
a. Data Ingestion & Storage
- Raw Video Dataset (external storage / local fs)
b. Preprocessing & Labeling
- Frame Extraction Module (images.py) → output: image frames
c. Data Splitting & Sampling
- Split Modules (split.py / split_balanced.py) → train/val/test sets
- Weighted Sampler (weightsampler.py) for balanced batch creation
d. Training & Fine-Tuning
- Training Engine (train.py)
- Fine-Tuning Script (finetune.py)
- Optional: PyTorch Lightning Integration (lightning.ipynb)
e. Evaluation & Inference
- Inference Runner (script.py)
- Metric Calculation and Visualization (notebooks)

Directional data flow: Raw Video → Preprocessing → Splits → Sampler → Training → Model → Evaluation/Inference.

##### Architectural Patterns & Design Principles
– Modular pipeline: separate scripts for each stage
– Experimentation layer (Jupyter notebooks) decoupled from production scripts
– Clear separation of data, model-training, and evaluation
– Reuse of utilities (images.py, videolabels.py, weightsampler.py) across experiments

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Data Store
    DataStore[(Raw Video Dataset)]:::external

    %% Data Preparation Layer
    FrameExtraction["Frame Extraction Module\n(images.py)"]:::dataPrep
    LabelAssignment["Label Assignment Module\n(videolabels.py)"]:::dataPrep
    Split["Train/Val/Test Split\n(split.py)"]:::dataPrep
    BalancedSplit["Balanced Split\n(split_balanced.py)"]:::dataPrep
    WeightedSampler["Weighted Sampler\n(weightsampler.py)"]:::dataPrep

    %% Training Layer
    Train["Training Engine\n(train.py)"]:::training
    FineTune["Fine-Tuning Script\n(finetune.py)"]:::training

    %% Evaluation / Inference Layer
    Inference["Inference Engine\n(script.py)"]:::evaluation

    %% Experimentation Layer
    subgraph "Experimentation / Analysis"
        direction TB
        DFdemo["End-to-End Demo Notebook\n(deepfake.ipynb)"]:::experimentation
        LSTM["LSTM Model Exploration Notebook\n(deepfake_lstm.ipynb)"]:::experimentation
        Lightning["PyTorch Lightning Notebook\n(lightning.ipynb)"]:::experimentation
        MultiSource["Multi-Source Balanced Training Notebook\n(train_balanced_multisource_deepfake.ipynb)"]:::experimentation
    end

    %% Data Flow
    DataStore --> FrameExtraction --> LabelAssignment --> Split --> WeightedSampler --> Train --> Inference
    LabelAssignment --> BalancedSplit --> WeightedSampler
    Train --> FineTune --> Inference

    %% Click Events
    click FrameExtraction "https://github.com/jeetpatil12/deepfake-detection/blob/main/images.py"
    click LabelAssignment "https://github.com/jeetpatil12/deepfake-detection/blob/main/videolabels.py"
    click Split "https://github.com/jeetpatil12/deepfake-detection/blob/main/split.py"
    click BalancedSplit "https://github.com/jeetpatil12/deepfake-detection/blob/main/split_balanced.py"
    click WeightedSampler "https://github.com/jeetpatil12/deepfake-detection/blob/main/weightsampler.py"
    click Train "https://github.com/jeetpatil12/deepfake-detection/blob/main/train.py"
    click FineTune "https://github.com/jeetpatil12/deepfake-detection/blob/main/finetune.py"
    click Inference "https://github.com/jeetpatil12/deepfake-detection/blob/main/script.py"
    click DFdemo "https://github.com/jeetpatil12/deepfake-detection/blob/main/deepfake.ipynb"
    click LSTM "https://github.com/jeetpatil12/deepfake-detection/blob/main/deepfake_lstm.ipynb"
    click Lightning "https://github.com/jeetpatil12/deepfake-detection/blob/main/lightning.ipynb"
    click MultiSource "https://github.com/jeetpatil12/deepfake-detection/blob/main/train_balanced_multisource_deepfake.ipynb"

    %% Styles
    classDef dataPrep fill:#ADD8E6,stroke:#000000,color:#000000
    classDef training fill:#90EE90,stroke:#000000,color:#000000
    classDef evaluation fill:#FFA500,stroke:#000000,color:#000000
    classDef experimentation fill:#D3D3D3,stroke-dasharray: 5 5,stroke:#000000,color:#000000
    classDef external fill:#CCCCCC,stroke:#000000,color:#000000
```
