DeepfakeBench

repository·main·Indexed 21 days ago

https://github.com/sclbd/deepfakebench

A comprehensive benchmarking platform for deepfake detection (NeurIPS 2023 D&B) providing a unified framework for training and evaluating state-of-the-art image and video detectors. It supports 36 detection methods across categories including Naive, Spatial, Frequency, and Video detectors, and integrates evaluation across 9 major datasets such as FaceForensics++ and Celeb-DF. The platform features multi-GPU training via DDP, high-speed IO using LMDB, and standardized metrics including frame-level and video-level AUC, ACC, EER, PR, and AP.

Tokens
5.5K
Snippets
16
Records
23
Agent score
77%

What's inside DeepfakeBench

  1. Overview of DeepfakeBench

    main

    DeepfakeBench is a comprehensive, unified benchmark platform for deepfake detection (NeurIPS 2023 D&B). It provides a standardized framework for implementing, training, and evaluating state-of-the-art (SoTA) detection methods for both images and videos.

    Key capabilities include:

    • Unified Platform: Standardizes deepfake detection benchmarking.
    • Data Management: A unified system ensuring consistent input across different models.
    • Integrated Framework: Supports training, data loading, and evaluation at both image and video levels.
    • Standardized Evaluations: Implements consistent metrics including frame-level AUC, video-level AUC, ACC (fake and real), EER, PR, and AP.
    • Advanced Features: Supports multi-GPU training via DDP (Distributed Data Parallel) and high-speed IO using LMDB.
  2. Available Detectors in DeepfakeBench

    main

    DeepfakeBench provides a comprehensive collection of 36 detectors categorized by their approach to deepfake detection. These include:

    • Naive Detectors (5): Xception, MesoNet, MesoInception, CNN-Aug, and EfficientNet-B4.
    • Spatial Detectors (20): Includes methods like Capsule, Face X-ray, FFD, CORE, RECCE, CLIP, SBI, and more.
    • Frequency Detectors (3): F3Net, SPSL, and SRM.
    • Video Detectors (8): TALL, I3D, STIL, FTCN, X-CLIP, TimeTransformer, and VideoMAE.

    Each detector is implemented as a Python module within the training/detectors/ directory.

  3. DeepfakeBench Features and Supported Detectors

    main

    DeepfakeBench (v2) supports a wide range of detection methods and technical features:

    Supported Detectors

    Currently supports 36 detection methods:

    • 28 image detectors
    • 8 video detectors

    Recent additions include SoTA detectors such as:

    • Effort (ICML'25 spotlight)
    • LSDA (CVPR'24)
    • AltFreezing (CVPR'23)
    • TALL (ICCV'23)
    • IID (CVPR'23)
    • SBI (CVPR'22)
    • SLADD (CVPR'22)
    • FTCN (ICCV'21)

    Technical Capabilities

    • Multi-GPU Training: Uses DDP for distributed training.
    • Fast IO: Provides LMDB support for efficient data loading.
    • Comprehensive Metrics: Evaluates performance using frame-level AUC, video-level AUC, ACC (fake and real), EER, PR, and AP.
  4. Preprocess datasets

    main

    Preprocessing involves face detection, alignment, and cropping.

    Note: If you use the pre-processed data provided by the authors, you can skip preprocess.py, but you must still run rearrange.py to generate the required JSON files.

    Steps to preprocess:

    1. Download shape_predictor_81_face_landmarks.dat and place it in ./preprocessing/dlib_tools.
    2. Edit ./preprocessing/config.yaml:
      • Set default to your target dataset name (e.g., FaceForensics++).
      • Set dataset_root_path to your actual dataset directory (default is ./datasets).
    3. Run the preprocessing script:
    cd preprocessing
    python preprocess.py
  5. Install DeepfakeBench via Conda or Docker

    main

    You can set up the environment using one of two methods:

    Option 1: Conda (Manual Setup)

    Clone the repository and use a Conda environment with Python 3.7.2. Run the provided install.sh script to complete the installation.

    Use the provided Dockerfile to ensure environment consistency. This method is recommended to avoid environment-related issues. Note that Docker version 19.03.14 was used for the original setup, though later versions may be compatible.

    # Option 1: Conda
    git clone git@github.com:SCLBD/DeepfakeBench.git
    cd DeepfakeBench
    conda create -n DeepfakeBench python=3.7.2
    conda activate DeepfakeBench
    sh install.sh
    
    # Option 2: Docker
    docker build -t DeepfakeBench .
    docker run --gpus all -itd -v /path/to/this/repository:/app/ --shm-size 64G DeepfakeBench
  6. Generate BI data using Face-X-ray re-implementation

    main

    This module provides an unofficial PyTorch re-implementation of the Face X-ray paper's BI (Blending Image) data generation pipeline. You can generate blended images by running the bi_online_generation.py script, which produces results consistent with Figure 5 in the original paper.

    To generate a complete BI dataset, you must first ensure all faces are cropped and landmarks are computed according to the logic defined in the codebase.

    python bi_online_generation.py
  7. Train a detector

    main

    To train a detector (e.g., Xception):

    1. Download Backbones: Download ImageNet pre-trained weights from the official release and place them in ./training/pretrained.
    2. Configure Detector: Edit the specific detector config file in ./training/config/detector/ (e.g., xception.yaml) to set parameters like epoch, frame_num, and dataset paths.
    3. Run Training: Use the training/train.py script.

    Special Case: Face X-ray detector Before training Face X-ray, you must generate a pickle file containing Top-N nearest images by running: python ./training/dataset/generate_xray_nearest.py.

    Multi-GPU Training: Refer to train.sh for DDP (Distributed Data Parallel) instructions.

    # Basic training
    python training/train.py --detector_path ./training/config/detector/xception.yaml
    
    # Training with specific datasets
    python training/train.py \
    --detector_path ./training/config/detector/xception.yaml  \
    --train_dataset "FaceForensics++" \
    --test_dataset "Celeb-DF-v1" "Celeb-DF-v2"
    
    # Training without saving checkpoints or features
    python training/train.py \
    --detector_path ./training/config/detector/xception.yaml \
    --train_dataset "FaceForensics++" \
    --test_dataset "Celeb-DF-v1" "Celeb-DF-v2" \
    --no-save_ckpt \
    --no-save_feat
  8. Generate dataset JSON configurations via Rearrangement

    main

    To enable unified data loading across different datasets, you must run the rearrangement script. This generates JSON files in ./preprocessing/dataset_json that organize videos by labels and data splits (train, test, validation).

    This step is required whether you are preprocessing your own raw data or using pre-processed data provided by the authors.

    cd preprocessing
    python rearrange.py
  9. Evaluate detectors

    main

    To perform cross-dataset evaluation, use training/test.py.

    Requirement: You must place pre-trained weights in the ./training/weights folder before running evaluation.

    python3 training/test.py \
    --detector_path ./training/config/detector/xception.yaml \
    --test_dataset "Celeb-DF-v1" "Celeb-DF-v2" "DFDCP" \
    --weights_path ./training/weights/xception_best.pth
  10. Analyze experimental results

    main
    The project provides experimental results for various detectors (Naive, Spatial, and Frequency types) across multiple datasets. You can perform further analysis on these results using the scripts provided in the ./analysis directory.
  11. Organize datasets for DeepfakeBench

    main

    Datasets must be stored in the ./datasets folder following a specific directory structure. You can use either Rgb-format or Lmdb-format datasets.

    If you store datasets in a non-default location, you must update the rgb_dir or lmdb_dir keys in training/test_config.yaml and training/train_config.yaml.

    Additionally, JSON configuration files (generated via the rearrangement step) must be placed in the ./preprocessing/dataset_json folder. If you use a different folder for these, update the dataset_json_folder key in the training config files.

    datasets
    ├── lmdb
    |   ├── FaceForensics++_lmdb
    |   |   ├── data.mdb
    |   |   ├── lock.mdb
    ├── rgb
    |   ├── FaceForensics++
    |   |   ├── original_sequences
    |   |   │   ├── youtube
    |   |   │   │   ├── c23
    |   |   │   │   │   ├── videos
    |   |   │   │   │   │   └── *.mp4
    |   |   │   │   │   └── frames (if processed)
    |   |   │   │   │   │   └── *.png
    |   |   │   │   │   │   └── masks (if processed)
    |   |   │   │   │   │   └── *.png
    |   |   │   │   │   └── landmarks (if processed)
    |   |   │   │   │   │   └── *.png