# taeyeonmik/vit_deepfake architecture

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

- Interactive diagram: https://gitdiagram.com/taeyeonmik/vit_deepfake
- Repository: https://github.com/taeyeonmik/vit_deepfake

## Overview

##### Project Type and Purpose
- This is a machine-learning pipeline for image classification (deepfake detection) combining two neural architectures: EfficientNet and Vision Transformer (ViT).
- It supports data loading, preprocessing, model training, testing, and inference, with Jupyter notebooks for exploratory analysis and result visualization.

##### File Structure
Top-level components:
- colab-notebooks – exploratory/training/inference notebooks
- efficient-vit – core ViT training & orchestration code
- efficientnet – standalone EfficientNet model code
- inference – (inference scripts for production/CLI usage)
- train-results – output graphs & metrics
- presentation.pdf – high-level project overview
- requirements.txt – Python dependencies

##### Files
- efficient-vit/configs/configuration.yaml – hyperparameters & paths
- efficient-vit/train.py – training loop combining EfficientNet + ViT
- efficient-vit/test.py – model evaluation/inference script
- efficient-vit/efficient_vit.py – model definition integrating both architectures
- efficient-vit/dataset.py – data-loading & preprocessing pipeline
- efficientnet/model.py, efficientnet/utils.py – EfficientNet building blocks

##### Main Components
a. Data Layer
- DFFD Dataset (raw images)
- Data ingestion & preprocessing (efficient-vit/dataset.py)
b. Model Layer
- EfficientNet submodule (efficientnet/model.py)
- Vision Transformer submodule (efficient-vit/efficient_vit.py)
- Combined architecture (feature fusion or classifier head)
c. Training Orchestrator
- train.py reading configuration.yaml
- Optimizer, scheduler, back-prop, checkpointing
d. Testing/Inference
- test.py command-line script
- Colab notebooks for exploratory inference (colab-notebooks/*.ipynb)
- Inference folder for deployment scripts
e. Results & Visualization
- train-results folder (plots, metrics)
- presentation.pdf

##### Relationships and Data Flows
- Dataset loader → Model input (batch of images)
- Model input → EfficientNet module → feature vectors
- Model input → ViT module → feature vectors
- Feature vectors → Fusion/Classifier → output logits
- Output → Loss & metric computation → back to Training orchestrator
- After training: checkpoint files → Google Drive (external storage)
- test.py / notebooks → Trained model → inference predictions → train-results

##### Architectural Patterns and Key Principles
- Modular separation: data ingestion, model definition, training orchestration, evaluation
- Configuration-driven design via YAML (separates code from hyperparameters)
- Reusable components: EfficientNet implemented once in `efficientnet/`, reused by ViT integration
- Notebook layer for research vs. CLI scripts for reproducible pipelines

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Data Layer
    subgraph "Data Layer"
        direction TB
        Dataset[("DFFD Dataset")]:::data
        Loader["Dataset Loader"]:::data
    end

    %% Model Layer
    subgraph "Model Layer"
        direction TB
        subgraph "EfficientNet Submodule"
            direction TB
            EffModel["Model definitions"]:::model
            EffUtils["Utilities"]:::model
        end
        Vit["Vision Transformer Module"]:::model
        Fusion["Fusion / Classifier"]:::model
    end

    %% Orchestration Layer
    subgraph "Training Orchestrator"
        direction TB
        Config["configuration.yaml"]:::orchestration
        Train["train.py"]:::orchestration
        SharedUtils["Shared Utilities"]:::orchestration
    end

    %% Evaluation / Inference Layer
    subgraph "Evaluation & Inference"
        direction TB
        Test["test.py"]:::orchestration
        Inference["Production CLI Scripts"]:::orchestration
    end

    %% Research Layer
    subgraph "Research Notebooks"
        direction TB
        NB1["Deepfake_SBIs_EfficientNet_ViT.ipynb"]:::research
        NB2["Deepfake_SBIs_EfficientNet_ViT_Infer.ipynb"]:::research
        NB3["Deepfake_ViT_graphiques.ipynb"]:::research
    end

    %% Results & Artifacts
    subgraph "Results & Artifacts"
        direction TB
        Results["train-results/"]:::storage
        Presentation["presentation.pdf"]:::research
    end

    %% Dependencies
    Requirements["requirements.txt"]:::dependency

    %% Connections
    Dataset -->|" .jpg images "| Loader
    Loader -->|"Tensor batches"| EffModel
    Loader -->|"Tensor batches"| Vit
    EffModel -->|"feature vectors"| Fusion
    Vit -->|"feature vectors"| Fusion
    Fusion -->|"logits"| Train
    Config -->|reads| Train
    SharedUtils -->|used by| Train
    Train -->|" .pt checkpoints"| Results
    Train -->|"external storage"| gDrive["Google Drive"]:::external
    Test -->|"loads .pt"| Fusion
    Test -->|"predictions"| Results
    NB1 -->|"uses model"| Fusion
    NB2 -->|"infer"| Fusion
    NB3 -->|"plots metrics"| Results
    Inference -->|"deploy model"| Fusion
    Requirements -->|dependency| Loader
    Requirements -->|dependency| EffModel
    Requirements -->|dependency| Vit
    Requirements -->|dependency| Train
    Requirements -->|dependency| Test
    Requirements -->|dependency| Inference
    Requirements -->|dependency| NB1
    Requirements -->|dependency| NB2
    Requirements -->|dependency| NB3

    %% Click Events
    click Loader "https://github.com/taeyeonmik/vit_deepfake/blob/main/efficient-vit/dataset.py"
    click Config "https://github.com/taeyeonmik/vit_deepfake/blob/main/efficient-vit/configs/configuration.yaml"
    click EffModel "https://github.com/taeyeonmik/vit_deepfake/blob/main/efficientnet/model.py"
    click EffUtils "https://github.com/taeyeonmik/vit_deepfake/blob/main/efficientnet/utils.py"
    click Vit "https://github.com/taeyeonmik/vit_deepfake/blob/main/efficient-vit/efficient_vit.py"
    click Train "https://github.com/taeyeonmik/vit_deepfake/blob/main/efficient-vit/train.py"
    click SharedUtils "https://github.com/taeyeonmik/vit_deepfake/blob/main/efficient-vit/utils.py"
    click Test "https://github.com/taeyeonmik/vit_deepfake/blob/main/efficient-vit/test.py"
    click Inference "https://github.com/taeyeonmik/vit_deepfake/tree/main/inference/"
    click NB1 "https://github.com/taeyeonmik/vit_deepfake/blob/main/colab-notebooks/Deepfake_SBIs_EfficientNet_ViT.ipynb"
    click NB2 "https://github.com/taeyeonmik/vit_deepfake/blob/main/colab-notebooks/Deepfake_SBIs_EfficientNet_ViT_Infer.ipynb"
    click NB3 "https://github.com/taeyeonmik/vit_deepfake/blob/main/colab-notebooks/Deepfake_ViT_graphiques.ipynb"
    click Results "https://github.com/taeyeonmik/vit_deepfake/tree/main/train-results/"
    click Presentation "https://github.com/taeyeonmik/vit_deepfake/blob/main/presentation.pdf"
    click Requirements "https://github.com/taeyeonmik/vit_deepfake/blob/main/requirements.txt"

    %% Styles
    classDef data fill:#ADD8E6,stroke:#000
    classDef storage fill:#ADD8E6,stroke:#000
    classDef model fill:#90EE90,stroke:#000
    classDef orchestration fill:#FFA500,stroke:#000
    classDef research fill:#DDA0DD,stroke:#000
    classDef dependency fill:#F0E68C,stroke:#000
    classDef external fill:#FFB6C1,stroke:#000,stroke-dasharray: 5 5
```
