Hardening Transformer Deepfake Detectors Against Attention Hijacking at a Fraction of Adversarial-Training Cost

Detectors of AI-generated images increasingly use vision transformers. These models cut an image into patches and let every patch "attend to," or weigh information from, every other patch. Many of these detectors look for spectral fingerprints: periodic, grid-like traces that generators leave in the high-frequency part of an image's Fourier spectrum, visible even when the pixels look clean. We conjecture that the cheapest way to fool such a detector is not to erase the fingerprint. It is to redirect the detector's attention. A small, mostly low-frequency perturbation pulls the transformer's attention onto a patch the attacker controls. The forgery evidence stays in the image, but the model stops looking at it. If that is true, the defense does not need to protect the whole network. It only needs to keep the shallow layers that decide where attention goes from being hijacked, and an attack on those layers costs a fraction of a full adversarial-training attack.

The proposal is to test this conjecture and to build a training recipe on it. In the recipe, the inner attack used during adversarial training maximizes attention onto an adversarial patch at an intermediate layer. Its gradients pass only through the first few transformer blocks, not the full network. The decisive question is whether a detector hardened this way survives a fully adaptive attacker who optimizes the final real-versus-fake decision end to end. A second question is whether it gets most of the robustness of full adversarial training for roughly a third of the compute.

Core Claim

The claim has two parts, and both can be falsified. The first part is diagnostic. When a white-box attacker evades a frequency-aware transformer detector, the successful perturbations concentrate in low-to-mid frequency bands. The attacked images still carry the generator's high-frequency fingerprint: an independent spectrum-only classifier still flags them as fake. Meanwhile, attention mass at intermediate layers shifts sharply toward a few patches.

The second part is constructive. If evasion runs through attention routing, then adversarial training whose inner attack targets that routing should close most of the gap to full projected-gradient adversarial training. Projected gradient descent (PGD) is the standard iterative attack, and PGD adversarial training retrains the model on PGD-perturbed inputs. The shallow inner attack backpropagates only to block $k$ of $L$, so it costs roughly $k/L$ of a full PGD step.

The diagnostic part rests on two findings that have not been put together. The first is that generator fingerprints are high-frequency upsampling artifacts (Frank et al.; Marra et al.). The second is that transformers, unlike CNNs, are most sensitive to low-to-mid frequency perturbations (Intriguing Frequency Interpretation of Adversarial Robustness for CNNs and ViTs). Together they predict a mismatch: the band where a transformer detector finds its evidence differs from the band where it is easiest to push around. If the prediction fails, and attacks instead scrub the high-frequency fingerprint, the constructive part loses its motivation. We would report that outcome as a result in its own right.

Relation to Prior Work

Three groups of papers frame the problem.

The first group motivates it.

  • Patch-Fool selects the most influential patch at an intermediate layer (layer 5 in DeiT) and optimizes a loss that drives attention onto it. Under a single-patch attack, DeiT-S robust accuracy falls to 6.25% on an ImageNet subset. Patch-Fool also reports that standard adversarial training leaves transformers less robust than CNNs. - Attacking Attention of Foundation Models maximizes the divergence between clean and perturbed attention to break dense prediction tasks.

Both papers work only on natural-image tasks, and both ignore the frequency content of the perturbation. We move the attack to forensic detectors whose evidence is spectral, and we measure what the attack does to that evidence.

The second group supplies the forensic architectures and constrains the design.

  • ObjectFormer fuses DCT high-pass features with RGB patch embeddings in a transformer. Removing the frequency branch costs 14.6% AUC on CASIA. It has never been attacked adversarially.
  • Frequency Masking for Universal Deepfake Detection masks 15% of spectral components during training and reaches 88.22% mAP on unseen generators. It is evaluated only on clean data.
  • FrePGAN trains a frequency-perturbation generator against a ResNet-50 detector. This is a full min-max GAN with heavy overhead and no attention mechanism.
  • D4 partitions DCT components across an ensemble. It shows as few as 6% of components suffice for detection, and it cuts SurFree attack success to 28%. However, it addresses only black-box query attacks on CNNs, and white-box adaptive robustness is left open.

The third group supplies cheap transformer defenses. These are our closest competitors.

  • RAM caps attention logits and randomly drops attention connections at inference, with no training. It was never tested against an attacker who averages gradients over the random drops. Averaging over the defense's random choices is called expectation-over-transformation (EOT).
  • Robustness Tokens trains ten appended tokens on a frozen backbone in 200 steps. It restores DINOv2-Giant from 0.3% to 63.1% under white-box attack, but its security depends on keeping the tokens secret.
  • Dynamic Attention randomizes attention rectification at inference, but only for text models.

Our proposal differs from all three. It changes the trained weights, so its security does not rest on secrecy or on randomness that EOT can average away. And it targets the specific internal mechanism that the diagnosis identifies.

The adaptive-attack literature constrains how we evaluate. DeepCloak concedes that an attacker aware of its static mask simply attacks the unmasked features. Optimizing Adaptive Attacks against Content Watermarks shows that defenses tested only against non-adaptive attackers give false assurance. We therefore treat every defense, including ours, as broken until an attacker who knows its mechanics fails against it.

Research Program

The first stage is the diagnosis. We train or adopt transformer detectors in three regimes:

  • a DeiT-S and a CLIP-backbone detector trained on the ProGAN benchmark, in the style of the CLIP-based detector that Frequency Masking integrates with;
  • ObjectFormer on its manipulation-localization setting;
  • a ResNet-50 detector as an architectural contrast.

We attack each detector three ways: full-depth PGD on the detection loss, Patch-Fool-style single-patch attention hijacking, and global attention-divergence attacks.

For every successful adversarial example we record four things:

  • the perturbation's energy across radial frequency bands;
  • the change in intermediate-layer attention entropy, and the attention mass on the most-attended patch;
  • the verdict of an independent, frozen spectrum-only fingerprint classifier in the style of Frank et al., which the attacker does not target;
  • the success rate of the same attack when we project the perturbation onto only low, only mid, or only high bands.

The conjecture is supported if three conditions hold for the transformer detectors and not for the ResNet: successful attacks are low-to-mid dominant, the fingerprint classifier still flags most attacked fakes, and attention concentrates.

The second stage is the defense, which we call shallow attention adversarial training. At each training step, the inner maximization picks the patch Patch-Fool's selection rule would pick and perturbs it, within a pixel budget, for a few steps. The objective is to maximize the attention mass that patch receives at block $k$:

$$\max_{\|\delta\| \le \epsilon} \; \sum_{h} \sum_{i} A^{(k)}_{h,i,p}(x+\delta),$$

Here $A^{(k)}_{h,i,p}$ is the attention weight that query patch $i$ in head $h$ of block $k$ places on the perturbed patch $p$. The maximization uses the attention weights of the first $k$ blocks, so gradients never pass beyond block $k$. The objective needs no labels. The outer step then updates the full network on the perturbed image. It uses the ordinary detection loss plus a term that penalizes attention concentration on $p$, while keeping clean-image attention close to the pre-trained model's.

The expected cost follows from depth. With $T$ inner steps and depth fraction $k/L$, the inner loop costs about $T k/L$ full forward-backward passes, against $T$ for PGD adversarial training. With $T=10$, $k=5$, and $L=12$, that is roughly 4 pass-equivalents instead of 10, before the outer step. We will report measured GPU-hours rather than rely on this estimate.

Baselines

The naive reference point is the undefended detector, trained normally on each benchmark and attacked with the same adaptive suite. It fixes how much robustness there is to recover. Clean numbers from the file give the scale. Frequency Masking reports 88.22% mAP on unseen generators from ProGAN training. FrePGAN reports 79.4% mean accuracy over seven unseen GANs. On FaceForensics++, XceptionNet reaches 99.26% on raw data and 81.00% on heavily compressed data (FaceForensics++). A collapse similar to the CNN case is likely: Adversarial Perturbations Fool Deepfake Detectors reports CNN detectors falling from above 95% to 0% under white-box Carlini-Wagner attacks.

The strongest competitor on robustness is full PGD adversarial training of the same transformer detector. It optimizes exactly the threat we evaluate, so it sets the robustness ceiling a cheaper method can hope to approach. We give it the same data, perturbation budget, number of epochs, and hyperparameter search budget as our method, and we report its GPU-hours. We found no reported result on Lacuna for PGD-adversarially-trained transformer deepfake detectors, so we must run it ourselves. Our method beats it in the sense that matters if two conditions both hold. Its robust accuracy against full-depth adaptive attacks must be within a few points of PGD adversarial training. And it must use at most about 40% of PGD adversarial training's training compute, at equal or better clean mAP on unseen generators.

The strongest cheap competitor is RAM, which needs no training at all. On ADE20K it cut the adversarial target mIoU of a Nonlocal ResNet-50 from 40.42% to 14.59%, at about a 0.15% clean cost. We insert it as a drop-in replacement for attention in the same detectors. We attack it with EOT over its random drops and with logit-cap-aware losses. Beating it means higher robust accuracy under these adaptive attacks, since that is the setting where its randomness is expected to fail.

We also include three further baselines:

  • Robustness Tokens, trained with its published 200-step budget and evaluated both with secret tokens and with tokens known to the attacker;
  • the D4 frequency-disjoint ensemble, evaluated in its original LSUN Bedroom plus diffusion setting under both its black-box attacks and our white-box adaptive suite;
  • a static high-pass-input detector.

Two ablations isolate the key ingredient. The first keeps the truncated depth $k$ but replaces the attention objective with the ordinary detection loss computed through a temporary head at block $k$. This separates "shallow and cheap" from "targets attention." The second runs the attention objective at full depth, which separates the depth saving from the objective. We also sweep $k$ over 2, 5, and 8 to trace the trade-off between cost and robustness.

Why not just…?

Why not just run full PGD adversarial training? It is the honest ceiling, and we include it as such. The cases against it are cost and a known limit. Patch-Fool reports that adversarially trained transformers remain more vulnerable than CNNs to attention-hijacking patches. A Frequency Perspective of Adversarial Robustness shows that frequency-constrained training trades clean accuracy for robustness. Clean accuracy on unseen generators is exactly what forensic deployment cannot give up. If PGD adversarial training matches our robustness at only modestly higher cost, the efficiency argument shrinks to a constant factor. The compute-matched comparison above will show this directly. We would then report the diagnosis as the main contribution.

Why not just high-pass filter the input so low-frequency attacks have nothing to grab? This is the most serious simple threat. If the diagnosis is right, a detector that sees only a static high-pass view, in the spirit of BiHPF (Jeong), removes the attacker's preferred band at zero training cost. Two things count against it. DeepCloak's own admission implies that a static band boundary simply moves the adaptive attacker into the remaining band. And Frequency Masking found that fixed bands generalize poorly across generators. Neither point is decisive for transformers. So we train the high-pass detector with the same backbone and budget, attack it with high-band-restricted adaptive PGD, and compare both its clean mAP on unseen generators and its robust accuracy. If it wins on both, we adopt it and drop our method.

Why not just use a drop-in attention fix like RAM or Robustness Tokens? Both are cheaper than any training. However, RAM relies partly on randomness that has not faced EOT attacks. Robustness Tokens states that its security depends on the tokens staying private. Our evaluation removes both crutches by giving the attacker the tokens and the dropout distribution. If either defense still holds up there, it is the better choice, and we will say so.

Why not just use single-step adversarial training? Single-step training is the usual cheap substitute for PGD, and it costs about as little as our shallow attack. It is run as an additional baseline at matched compute. What separates it from our proposal is the target: it perturbs along the gradient of the final loss, not along the attention-routing direction the diagnosis identifies. If it matches our robustness, the attention objective adds nothing and the depth-truncation idea is the only contribution.

Proposed Experiments and Decisive Checks

The benchmarks follow the file. For universal synthetic-image detection, we train on the ProGAN benchmark and test on unseen GANs and diffusion models. We use FaceForensics++ at the c23 and c40 compression levels. We test diffusion-image robustness on LSUN Bedroom with LDM, DDIM, and PNDM generations, as in D4. We test manipulation localization on CASIA and NIST16 with ObjectFormer.

Four kinds of metrics are reported:

  • clean mAP or accuracy, and clean localization AUC;
  • robust accuracy, or attack success rate, under each attack at matched budgets;
  • spectral-fingerprint retention, measured by the independent fingerprint classifier;
  • training GPU-hours and inference latency.

The adaptive suite contains seven attacks:

  • full-depth PGD on the detection loss;
  • PGD on the detection loss plus our attention penalty, so the attacker optimizes against the defense's own regularizer;
  • Patch-Fool at every layer, not just the trained block $k$;
  • band-restricted PGD in each of the low, mid, and high bands;
  • EOT for any stochastic baseline;
  • the black-box SurFree and Triangle attacks for comparison with D4;
  • attacks crafted on a surrogate model and transferred.

Three outcomes would decide the proposal. First, the diagnosis must hold: on undefended transformer detectors, successful attacks are low-to-mid dominant and leave the fingerprint classifier's verdict largely intact, while the ResNet contrast does not show this pattern. Second, attacking a different layer than the one trained must not break the defense. If Patch-Fool at block $k+3$, or full-depth PGD, restores near-undefended attack success, the defense has merely moved the weak point, and the claim fails. Third, the compute-matched comparison must show the shallow method within a few points of PGD adversarial training on robust accuracy, at about 40% or less of its training compute, and ahead of the static high-pass detector and the single-step baseline. If only the first outcome holds, the work still yields a useful negative map of where transformer forensic detectors break. If all three hold, it gives the field a cheap way to harden them, tested against adaptive attackers.