# ondyari/faceforensics architecture

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

- Interactive diagram: https://gitdiagram.com/ondyari/faceforensics
- Repository: https://github.com/ondyari/faceforensics

## Overview

##### Project type and purpose
- This is not a web or microservice application but a research‑focused machine learning pipeline and dataset management toolkit.
- Purpose: Provide and generate manipulated facial video/image datasets (DeepFakes, Face2Face, FaceSwap, NeuralTextures, FaceShifter, etc.) and demonstrate a sample classification pipeline to detect forgeries.

##### File structure
- Top‑level:
- LICENSE, README.md – public information
- classification/ – sample classification demo
- dataset/ – dataset management, download, generation, extraction scripts, and sub‑repos for each manipulation method
- images/ – static assets (README illustrations)
- classification/ subfolders:
- classification/dataset – data loader and transform utilities
- classification/network – model definitions (Xception, custom models)
- detect_from_video.py – end‑to‑end inference script
- requirements.txt – Python dependencies for classification
- dataset/ subfolders:
- DeepFakeDetection, DeepFakes (faceswap-master), FaceShifter, FaceSwapKowalski, NeuralTextures – each with their own README, code, plugins and tools
- general scripts: compress.py, extract_compressed_videos.py, generate_original_images_from_downloaded_videos.py
- conversion_dict.json, splits/*.json – configuration and data splits
- setup_ffmpeg_h264.sh, setup.sh – environment setup scripts

##### README insights
- Core functions: dataset download, dataset generation (face‑swap pipelines), benchmark evaluation, classification sample.
- Dependencies: Dockerfiles exist for CPU/GPU faceswap builds; Python ML frameworks implied (likely TensorFlow or PyTorch) in classification.

##### Main components
a. Data Ingestion & Generation
- Original raw videos (YouTube source)
- Download script (dataset/README.md)
- Face manipulation modules (DeepFakes, Face2Face, FaceSwap, NeuralTextures, FaceShifter)
- Dataset scripts: video compression, extraction, splitting
b. Data Storage
- On‑disk directory structure under dataset/
- Versioned subfolders per manipulation method
- JSON split files for train/val/test
c. Data Processing & Transformation
- classification/dataset/transform.py – image/video frame transforms (resize, normalization)
- Dataset loader (classification/dataset/__init__.py)
d. Model Training & Inference
- classification/network/models.py – generic model wrappers
- classification/network/xception.py – Xception architecture for classification
- detect_from_video.py – inference pipeline combining loader, model, output
e. External Tools & Environments
- Docker (faceswap-master Dockerfiles)
- FFmpeg (setup_ffmpeg_h264.sh)
- GPU/CPU execution contexts

##### Relationships and interactions
- Data ingestion → dataset generation modules → processed/manipulated video files
- Processed files + splits → classification dataset loader → preprocessed tensors
- Preprocessed tensors → model training (Xception, other nets) → trained weights
- Trained weights + inference script → detection results on new videos
- Environment scripts and Docker images feed into dataset generation and execution contexts

##### Architectural patterns and design principles
- Pipeline pattern: clearly separated stages (ingest → generate → preprocess → train → infer)
- Modular structure: each face‑swap method encapsulated in its own subfolder, plugin architecture in faceswap-master/plugins
- Reusability: shared transform utilities, generic model wrappers

##### Relevant technologies and libraries
- Python 3.x
- Deep learning framework (TensorFlow or PyTorch inferred from network scripts)
- Docker for containerized builds of face‑swap tools
- FFmpeg for video decoding/encoding
- JSON for configuration (splits, conversion dict)

## Diagram (Mermaid)

```mermaid
flowchart TD
    Raw["Raw Videos (YouTube)"]:::data

    subgraph "Data Ingestion & Download"
        readme["README.md"]:::data
        gen_orig["generate_original_images_from_downloaded_videos.py"]:::data
        extract["extract_compressed_videos.py"]:::data
        compress["compress.py"]:::data
    end

    Raw --> readme
    readme --> gen_orig
    gen_orig --> extract
    extract --> compress

    subgraph "Face Manipulation Modules"
        deepfakes["DeepFakes (deepfakes.py)"]:::data
        faceswap_master["faceswap-master/"]:::data
        faceshifter["FaceShifter/"]:::data
        fs_kowalski["FaceSwapKowalski (faceswap.py)"]:::data
        fs_kow_dir["FaceSwapKowalski/FaceSwap/"]:::data
        neural["NeuralTextures/"]:::data
        df_detection["DeepFakeDetection/"]:::data
    end

    compress --> deepfakes
    compress --> faceshifter
    compress --> fs_kowalski
    compress --> fs_kow_dir
    compress --> neural
    compress --> df_detection
    deepfakes --> faceswap_master

    subgraph "Dataset Configuration & Storage"
        conv["conversion_dict.json"]:::data
        train["train.json"]:::data
        val["val.json"]:::data
        test["test.json"]:::data
    end

    compress --> conv
    compress --> train
    compress --> val
    compress --> test

    subgraph "Data Processing & Transformation"
        loader["__init__.py"]:::processing
        transform["transform.py"]:::processing
    end

    train --> loader
    train --> transform

    subgraph "Model Training & Definitions"
        models["models.py"]:::model
        xception["xception.py"]:::model
    end

    transform --> models
    transform --> xception

    inference["detect_from_video.py"]:::model
    xception --> inference

    subgraph "External Tools & Environments"
        ffmpeg["setup_ffmpeg_h264.sh"]:::tool
        docker_cpu["Dockerfile.cpu"]:::tool
        docker_gpu["Dockerfile.gpu"]:::tool
        setup_all["setup.sh"]:::tool
    end

    ffmpeg -.-> compress
    docker_cpu -.-> faceswap_master
    docker_gpu -.-> faceswap_master
    setup_all -.-> readme
    setup_all -.-> gen_orig
    setup_all -.-> deepfakes

    images["images/"]:::data

    classDef data fill:#CEF6FF,stroke:#036;font-weight:bold
    classDef processing fill:#D5F5E3,stroke:#060,font-weight:bold
    classDef model fill:#F9E79F,stroke:#984,font-weight:bold
    classDef tool fill:#D8D8D8,stroke:#666,font-weight:bold

    click readme "https://github.com/ondyari/faceforensics/blob/master/dataset/README.md"
    click gen_orig "https://github.com/ondyari/faceforensics/blob/master/dataset/generate_original_images_from_downloaded_videos.py"
    click extract "https://github.com/ondyari/faceforensics/blob/master/dataset/extract_compressed_videos.py"
    click compress "https://github.com/ondyari/faceforensics/blob/master/dataset/compress.py"
    click deepfakes "https://github.com/ondyari/faceforensics/blob/master/dataset/DeepFakes/deepfakes.py"
    click faceswap_master "https://github.com/ondyari/faceforensics/tree/master/dataset/DeepFakes/faceswap-master/"
    click faceshifter "https://github.com/ondyari/faceforensics/tree/master/dataset/FaceShifter/"
    click fs_kowalski "https://github.com/ondyari/faceforensics/blob/master/dataset/FaceSwapKowalski/faceswap.py"
    click fs_kow_dir "https://github.com/ondyari/faceforensics/tree/master/dataset/FaceSwapKowalski/FaceSwap/"
    click neural "https://github.com/ondyari/faceforensics/tree/master/dataset/NeuralTextures/"
    click df_detection "https://github.com/ondyari/faceforensics/tree/master/dataset/DeepFakeDetection/"
    click conv "https://github.com/ondyari/faceforensics/blob/master/dataset/conversion_dict.json"
    click train "https://github.com/ondyari/faceforensics/blob/master/dataset/splits/train.json"
    click val "https://github.com/ondyari/faceforensics/blob/master/dataset/splits/val.json"
    click test "https://github.com/ondyari/faceforensics/blob/master/dataset/splits/test.json"
    click loader "https://github.com/ondyari/faceforensics/blob/master/classification/dataset/__init__.py"
    click transform "https://github.com/ondyari/faceforensics/blob/master/classification/dataset/transform.py"
    click models "https://github.com/ondyari/faceforensics/blob/master/classification/network/models.py"
    click xception "https://github.com/ondyari/faceforensics/blob/master/classification/network/xception.py"
    click inference "https://github.com/ondyari/faceforensics/blob/master/classification/detect_from_video.py"
    click ffmpeg "https://github.com/ondyari/faceforensics/blob/master/dataset/setup_ffmpeg_h264.sh"
    click docker_cpu "https://github.com/ondyari/faceforensics/blob/master/dataset/DeepFakes/faceswap-master/Dockerfile.cpu"
    click docker_gpu "https://github.com/ondyari/faceforensics/blob/master/dataset/DeepFakes/faceswap-master/Dockerfile.gpu"
    click setup_all "https://github.com/ondyari/faceforensics/blob/master/dataset/setup.sh"
    click images "https://github.com/ondyari/faceforensics/tree/master/images/"
```
