FakeFormer: Efficient Vulnerability-Driven Transformers for Generalisable Deepfake Detection

Dat Nguyen, Marcella Astrid, Enjie Ghorbel, Djamila Aouada

TL;DR

Vision Transformers (ViTs) typically underperform compared to CNNs in deepfake detection because their global attention mechanism overlooks localized forgery artifacts. This paper introduces FakeFormer, a framework that equips ViTs with a lightweight, learning-based local attention module (L2-Att) to explicitly target artifact-vulnerable image patches. The result is a highly efficient model that sets new state-of-the-art standards for cross-dataset generalization without requiring massive training datasets.

What Problem Does This Paper Address?

While Vision Transformers (ViTs) have taken over general image classification, they have historically lagged behind Convolutional Neural Networks (CNNs) when it comes to spotting deepfakes. The authors investigate this performance gap and identify a core architectural mismatch: deepfakes are characterized by highly localized, subtle artifacts (such as blending boundaries around the eyes, nose, or mouth), but ViTs are inherently biased toward learning global context.

As deepfake generation techniques improve, these localized artifacts become even more microscopic. Standard ViTs simply look at the "big picture" and miss the tiny inconsistencies that reveal a forgery.

Examples of different deepfake types in the FF++ dataset, showing varying levels of subtle artifacts.

Methods

To bridge this gap, the authors propose FakeFormer, which introduces a Learning-based Local Attention (L2-Att) mechanism into the standard ViT pipeline.

Instead of relying on the model to implicitly discover where to look, FakeFormer explicitly trains the network to find vulnerable patches—the regions most likely to contain blending artifacts.

  1. Vulnerable Patch Generation: During training, the framework uses automated blending-based data synthesis to create pseudo-deepfakes. By analyzing the blending boundary, it identifies the exact patches with the highest mixture magnitude between the source and target faces.
  2. L2-Att Module: This module takes the patch embeddings from the final transformer layer, reshapes them back into a 2D spatial grid, and passes them through a few lightweight convolutional blocks. It outputs a heatmap predicting the locations of these vulnerable patches.
  3. Joint Optimization: The network is trained using a dual loss function: a standard binary cross-entropy loss for the final real/fake classification, and a focal loss to supervise the L2-Att heatmap prediction.

This architecture allows the model to retain the global modeling power of transformers while forcing it to pay close attention to local, inconsistency-prone details.

The FakeFormer framework, detailing the L2-Att module and the vulnerable patch generation process.

Datasets

The model was trained strictly on the FaceForensics++ (FF++) dataset using only real videos and dynamically synthesized pseudo-fakes.

To evaluate generalization, the authors conducted extensive cross-dataset testing on several challenging benchmarks:

  • Celeb-DF (CDF1, CDF2) (High-quality deepfakes)
  • WildDeepfake (DFW) (Real-world internet deepfakes)
  • DeepFakeDetection (DFD)
  • Deepfake Detection Challenge Preview (DFDCP) & DFDC (Large-scale benchmarks)

Key Insights and Ideas

  • The Quality Paradox: The authors show that as deepfake quality increases (measured by higher Mask SSIM values), standard ViT performance plummets drastically compared to CNNs. This confirms that ViTs fail precisely where artifacts are most localized.
  • Patch Size vs. Complexity: While reducing a ViT's patch size (e.g., from 16x16 to 8x8) helps it capture local details and converge faster, it increases computational complexity quadratically. FakeFormer avoids this brute-force approach by using larger patches but guiding attention intelligently.
  • Patches over Points: Previous CNN-based attention methods targeted pixel-level "vulnerable points," requiring heavy, computationally expensive decoders. By upgrading this concept to a patch-level mechanism, FakeFormer eliminates the need for a heavy decoder, making it incredibly lightweight.
Performance comparison across different Mask SSIM ranges and training loss evolution for various patch sizes.

Key Results

FakeFormer achieves a remarkable balance of high accuracy, strong generalization, and low computational overhead:

  • State-of-the-Art Generalization: When trained on FF++ and tested on the challenging Celeb-DF (CDF2) dataset, FakeFormer-S achieved an AUC of 94.45%, outperforming standard ViT-B (82.33%) and specialized transformer architectures like TALL-Swin (90.79%).
  • Efficiency Gains: The lightweight variant, FakeFormer-S, requires only 23M parameters and 8.9G FLOPs—a fraction of the computational cost of competing transformer models, which often exceed 80M parameters and 50G FLOPs.
Comparison of FakeFormer variants against existing methods in terms of FLOPs, parameters, and AUC.

Limitations and Future Work

Because FakeFormer's attention mechanism is explicitly tailored to detect blending boundaries (common in face-swaps and reenactments), it struggles against fully synthetic images generated from scratch (e.g., StyleGAN2). When tested on entirely synthetic faces, its performance drops to near-random guessing (~50.84% AUC).

The authors note that future work will focus on extending FakeFormer to capture temporal video dynamics and developing strategies to counter entirely synthetic deepfake generations.

Summary updated

BibTeX
@misc{nguyen2024fakeformer,
  author = {Dat NGUYEN and Marcella Astrid and Enjie Ghorbel and Djamila Aouada},
  title = {{FakeFormer: Efficient Vulnerability-Driven Transformers for Generalisable Deepfake Detection}},
  year = {2024},
  eprint = {2410.21964},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2410.21964},
}
Figure