Processing-History Adversaries for Deepfake Detection

Detectors of AI-generated images and videos often learn the wrong thing. In training sets, real photos have usually passed through a camera and been saved as JPEG several times, while generated images come straight out of the generator as lossless files. A detector can reach near-perfect benchmark accuracy just by learning to recognize a file's processing history (how it was compressed, resized and re-encoded), without learning anything about generation. Once images circulate on social media, every file gets re-encoded and that cue disappears. This is the same failure that robotics and perception researchers call the synthetic-to-real gap: a model trained on clean simulated data latches onto "clean versus noisy" rather than the task. The proposal borrows that field's most direct fix. We train an adversary that picks degradations specifically to break whatever nuisance cue the model is using, rather than degrading data at random.

Concretely, we train a deepfake detector against a learned adversary. The adversary chooses, separately for real and fake images, a sequence of plausible transmission operations: resizing, JPEG at chosen qualities, chroma subsampling, double compression, sharpening, and platform-style re-encoding. Its goal is to maximize the detector's error. If the detector relies on processing history, the adversary can reverse the usual correlation, for example by heavily compressing fakes and leaving reals pristine. The detector can only win by becoming indifferent to history. We also release a "history-flip" stress test that measures how much any existing detector depends on this shortcut.

Core Claim

The deepfake forensics literature treats compression and re-encoding as something to add at evaluation time, or to sample uniformly during training. We claim that the harmful part is not the degradation itself. The harm comes from any statistical dependence between processing history and the real/fake label. Uniform, class-independent augmentation removes that dependence only on average and only along the axes it samples. An adversary that can choose different histories for each class searches out and removes the dependences that remain.

This targets the "shortcut dilemma" named in the sim-to-real literature, where removing one shortcut leads the model to exploit the next. In our setting the obvious example is matching JPEG quality between classes while resize history or chroma subsampling still differs. The claim is falsifiable. If class-independent random augmentation matches the adversarial method on in-the-wild data and on the history-flip test, the claim is wrong.

Where This Sits

The motivating evidence comes from four forensics papers that each found a laboratory-to-wild gap.

Real-Time Deepfake Detection in the Real-World shows that the JPEG-versus-PNG asymmetry turns detectors into "JPEG detectors". It introduces WildRF, a set of about 5,000 images scraped from Reddit, X and Facebook. It also introduces a patch-based detector, LaDeDa, that judges small 9×9 pixel patches and scores 98.9% mean average precision (mAP) on standard benchmarks versus 93.7% on WildRF. Those authors respond by restricting the model's receptive field. We instead change the training distribution the model sees, and the change applies to any architecture, LaDeDa included.

Deepfake Videos in the Wild collects DF-W, a set of 1,869 deepfake videos scraped from YouTube, Bilibili and Reddit. It shows supervised detectors falling below 77% F1 on DF-W and recovers 91% F1 by fine-tuning on 50 wild videos. That fix is reactive, whereas ours happens during initial training.

FaceForensics++ reports accuracy dropping from 99.26% on raw video to 81.00% on heavily compressed video. DeeperForensics-1.0 adds 7 perturbation types at 5 intensities but samples them without regard to class, and still observes generalization gaps. Its perturbation set is the natural random-augmentation baseline for us, and our adversary's action space extends it.

The method comes from Adversarially Masking Synthetic to Mimic Real, known as ASM. ASM showed that in synthetic-to-real LiDAR segmentation, domain discriminators exploit the presence or absence of sensor noise as a shortcut. Its remedy is to learn, with a Gumbel-Softmax relaxation (a trick that makes discrete choices trainable by gradient descent), where to inject real-like dropout into clean synthetic scans. Its ablations also show that learned injection beats random injection. We reuse the Gumbel-Softmax machinery, applied to discrete choices of transmission operations instead of point dropout.

We make two changes to ASM. First, the adversary's objective is the detector's own real/fake loss, not a domain discriminator. Second, the adversary acts on both classes, because in forensics the shortcut is a correlation between history and label rather than a gap between two domains.

ASM also constrains our expectations. Even after adaptation, it leaves a large gap to supervised training on real data (22.8% versus 55.5% mean intersection-over-union on SynLiDAR → SemKITTI). We therefore do not expect adversarial history training to replace in-the-wild fine-tuning. We expect it to shrink how much fine-tuning is needed.

Two further works are complementary: frequency-domain synthetic fakes from FreqBlender, and artifact-free fakes from Fooling State-of-the-Art Deepfake Detection with High-Quality Deepfakes. Both change what kind of fakes the detector sees, while we change what history all images carry, so the approaches stack.

One paper appears to contradict our premise and sets its limits. A Taxonomy of Miscompressions shows that neural image codecs, compressors that reconstruct images with a GAN or diffusion model, produce reconstructions that look pristine but are semantically false. For example, the codec turned a sign's 2264 into 2254, and people in a scene vanished. For our method, this means some processing histories inject genuine generative traces into real photos. We therefore treat neural codecs as a separately reported operation rather than a label-neutral nuisance. The adversary is forbidden from using them during training, and we measure false-positive rates on codec-processed real images as a boundary case. Semantic hallucinations of this kind are outside what any history-invariant texture detector can catch, and we say so.

Research Program

Let $x$ be an image with label $y \in \{\text{real}, \text{fake}\}$, $f_\theta$ the detector with parameters $\theta$, and $T$ a transmission pipeline. Each pipeline is a short sequence of operations and parameters drawn from a finite library $\mathcal{T}$ of platform-plausible operations. The adversary is a pair of class-conditional policies $\pi_\phi(T \mid y)$ with parameters $\phi$. Training solves

$$\min_\theta \max_\phi \; \mathbb{E}_{(x,y)}\, \mathbb{E}_{T \sim \pi_\phi(\cdot \mid y)} \big[\ell(f_\theta(T(x)), y)\big] \;-\; \lambda\, \mathrm{KL}\big(\pi_\phi(\cdot\mid y)\,\|\,\pi_0\big),$$

where $\ell$ is cross-entropy and $\pi_0$ is a broad reference distribution over pipelines. The Kullback–Leibler (KL) term, weighted by $\lambda$, keeps the adversary from settling on degenerate histories such as quality-1 JPEG. Operation choices are relaxed with Gumbel-Softmax as in ASM. JPEG quantization uses a standard differentiable approximation, with a check against the true encoder at evaluation time.

Two design choices matter. First, the policies are class-conditional, since that is exactly what lets the adversary expose history–label dependence. Second, the operation library is built from inspecting the re-encoding each target platform actually applies. We fit this library on platforms disjoint from those in WildRF so that the evaluation is not leaked.

The second deliverable is the history-flip test. For any held-out set, we re-render every image under two conditions. In the matched condition, both classes are drawn from the same pipeline distribution. In the flipped condition, fakes receive the heavier, real-like histories and reals receive the lighter ones. A detector's flip gap is its AUC in the matched condition minus its AUC in the flipped condition. This gap is a direct, architecture-agnostic measure of shortcut reliance, and we will report it for every baseline, including published checkpoints.

We run two tracks with the same method. The image track trains on the ForenSynth and UFD generated-image benchmarks used by Real-Time Deepfake Detection in the Real-World and evaluates on WildRF. The face-video track trains on FaceForensics++ and evaluates cross-dataset on Celeb-DF, on DFDC, and on DF-W. On DF-W we also report F1 separately by FairFace demographic group, because Pu et al. found 48% F1 on Asian faces versus about 73% on Caucasian and Black faces. That lets us check whether history invariance changes the disparity, and we have no prior expectation about the direction.

Baselines

Naive reference. The simplest reference point is the same backbone trained on the raw training benchmark with no degradation. On the face track, published numbers show what this looks like: FaceForensics++-trained detectors average 56.9% AUC on Celeb-DF according to Celeb-DF.

Random augmentation. This is the strongest cheap competitor. We sample the DeeperForensics-style perturbation family, extended to our full operation library, independently of class and uniformly from $\pi_0$. It gets the same backbone, epochs and hyperparameter search budget as our method. Beating it means a higher WildRF mAP and a smaller flip gap with non-overlapping seed confidence intervals.

Format matching. This is the most direct fix for the JPEG shortcut. Every training image in both classes is re-encoded through one identical pipeline before augmentation.

LaDeDa. This is the strongest published image detector for the wild setting: 93.7% mAP on WildRF, reported by Real-Time Deepfake Detection in the Real-World. We retrain LaDeDa ourselves under its published recipe and then again with our adversary. That tests whether adversarial histories help even an architecture designed to ignore global context. Beating it means exceeding 93.7% WildRF mAP with the same training data.

FreqBlender. On the face track, the strongest existing method is FreqBlender, which reports 94.59% AUC on Celeb-DF and 74.59% on DFDC when trained on FaceForensics++, per FreqBlender. We combine it with our adversary rather than only competing against it. The decisive comparison is FreqBlender alone versus FreqBlender plus adversarial histories, with the gain concentrated on DFDC and DF-W, where transmission is messier.

DANN. We include DANN-style feature alignment, with WildRF-disjoint unlabeled social-media images as the target domain. We found no reported result on Lacuna for DANN on deepfake detection. The only evidence we have is from other domains, where PixelDA reports DANN at 56.58° mean angle error on LineMod versus 23.5° for pixel-level adaptation.

Few-shot fine-tuning. As an upper reference rather than a competitor, we fine-tune on 50 DF-W videos, which Pu et al. report raises F1 from 77% to 91%. We measure how many wild videos each method needs to reach 91%.

Ablations. Three ablations isolate the key ingredient. The first ties the two class policies together, so the adversary must degrade reals and fakes identically. This keeps the learned, worst-case search but removes class asymmetry, so the comparison separates "adversarial" from "class-conditional". The second replaces the learned adversary with random search over pipelines at equal compute. The third removes the KL term.

Why not just…?

Why not just augment with random JPEG, blur and noise? This is the most serious threat, and we treat it as the main hypothesis to beat, not a strawman. Two pieces of existing evidence suggest it falls short. DeeperForensics-1.0 trained with seven perturbation families and still saw drops on unseen conditions, and ASM's ablations found random injection weaker than learned injection. However, both concern different failure modes, so neither is decisive here. The random-augmentation baseline and the tied-policy ablation settle the question directly. If random augmentation reaches the same flip gap and WildRF mAP, the adversary is unnecessary and we will report that.

Why not just format-match the two classes? Matching one pipeline removes the documented JPEG asymmetry. It does not remove differences the matching pipeline leaves intact: camera-pipeline traces present only in reals, resize history, or chroma layout. It also fixes a single history that the wild will not reproduce. The flip test run against a format-matched detector will show whether residual history dependence survives. If it does not, format matching wins on simplicity.

Why not just fine-tune on a handful of wild samples? It works: 77% to 91% F1 in Deepfake Videos in the Wild, and 86.2% AUC after "vaccination" in Fooling State-of-the-Art Deepfake Detection with High-Quality Deepfakes. But it requires collecting fakes after they have already spread. The approaches are not exclusive, so our claim is about sample efficiency, measured by the number of wild videos needed to reach 91% F1.

Why not just use a small-patch detector like LaDeDa? Restricting the receptive field removes scene-level cues but not history cues, since compression lives exactly at the patch scale. Its 5-point drop from clean benchmarks to WildRF suggests residual reliance on history. We test this by measuring LaDeDa's flip gap and retraining it with our adversary.

Decisive Experiments

The central check is the flip gap. For our method to be worth doing, adversarially trained detectors must show a flip gap near zero where random-augmentation and format-matched detectors do not. That improvement must also carry over to data we did not construct: WildRF mAP above LaDeDa's 93.7%, and DF-W F1 above the 77% unadapted level, both with no wild training data.

The tied-policy ablation must lose to the class-conditional version. Otherwise the benefit comes from harder augmentation, not from breaking the correlation between history and label.

We will separately report false-positive rates on real images passed through the HiFiC and CDC neural codecs. That is where history invariance should not be expected to help, and those numbers mark the method's boundary.