Manuscript Offprint

arXiv:2609.31514

Forensic Twins: Self-Supervised Residual Learning for AI-Generated Image Forensics

Javier Muñoz-Haro, Ruben Tolosana, Ruben Vera-Rodriguez, Aythami Morales, Julian Fierrez

ABSTRACT

Detectors of AI-generated images are typically trained using samples from all Generative AI architectures they must catch, and struggle as soon as a new architecture emerges. Recent approaches have explored self-supervised pre-training as an alternative solution, yet standard frameworks work against the forensic task, e.g., their augmentations overwrite the micro-statistics of image formation. This paper introduces Forensic Twins, a Self-Supervised Residual Learning (SSRL) framework whose pretext task suppresses macroscopic content availability. Each image is mapped through a frozen, off-the-shelf forensic residual extractor, from which two spatially disjoint crops are drawn. Sharing no pixel, the two views retain minimal semantic structure to align, leaving a redundancy-reduction objective with a predominant common signal: the stationary fingerprint of the image acquisition pipeline. Additionally, Forensic Twins is trained exclusively on real images; no AI-generated image is observed at any stage. Experiments show that Forensic Twins attributes AI generator sources with 56.61% accuracy, i.e., 6.13% above the previous state-of-the-art zero-shot method at 375×375 \times lower latency. We also demonstrate that fitting a Gaussian Mixture Model (GMM) offline using only the real image embeddings extracted from Forensic Twins turns it into a state-of-the-art zero-shot detector, reaching 97.99% AUC across 27 unseen AI generators, including GANs, diffusion models and commercial systems. Code, weights and exact splits will be made publicly available 1^{1}.

1 INTRODUCTION

Generative models now synthesize images with unprecedented detail (Croitoru et al., 2023; Sauer et al., 2022; Alaluf et al., 2022; Tolosana et al., 2020) and increasing physical and semantic coherence (Avrahami et al., 2022), so realistic synthetic media can be deployed at scale. Condition-guided generation, from text prompts (Rombach et al., 2022; Dhariwal & Nichol, 2021) or reference images (Baliah et al., 2025), further lets them replicate structural layouts (Cao et al., 2025; Zhang et al., 2024), emulate artistic styles (Gao et al., 2026), or inject novel entities into authentic contexts (Chen et al., 2023; 2025; Zhao et al., 2024).

Supervised detectors (Tan et al., 2024; Wang et al., 2020b; Ojha et al., 2023) degrade in Out-of-Distribution Detection (OOD) scenarios (Park et al., 2024) and fail to generalize to unseen generators: handcrafted forensic priors and binary objectives push them to overfit to source-specific artifacts. Recent methods instead i) treat semantics and forensic traces as decorrelated spaces (Yan et al., 2025; Guo et al., 2026), or ii) model the manifold (Zhang et al., 2025) or descriptors (Nguyen et al., 2025) of natural images, relying on massively parameterized backbones such as DINOv2 (Oquab et al., 2024) and CLIP (Radford et al., 2021), or on costly Test-Time Optimization (TTO).

Self-Supervised Learning (SSL) (Gui et al., 2024) is thus a compelling alternative, learning generalizable representations from unannotated data without costly, biased labeling. Yet standard frameworks such as Barlow Twins (BT) (Zbontar et al., 2021), Momentum Contrast (MoCo) (He et al., 2020; Chen et al., 2020) and Self DIstillation with NO Labels (DINO) (Caron et al., 2021; Oquab et al., 2024; Simeoni et al., 2025) transfer poorly to forensics: they minimize the cross-view loss through semantic shortcuts, discarding the low-amplitude, micro-statistical noise intrinsic to natural image formation (Wang et al., 2020b; Marra et al., 2019; Sinitsa & Fried, 2024).

1^{1}The link will be provided upon acceptance.

Figure

DT 1: AI-Generated Images Detection

DT 2: Unsupervised Clustering of Image Sources

Figure 1: Overview of Forensic Twins and applications. Top: Real RGB images (X) undergo non-destructive augmentations (T) and residual filtering (F). Then, two strictly disjoint crops ( R1R_1, R2R_2) pass through a ViT ( fθf_\theta) and a projector ( gϕg_\phi), trained with a redundancy-reduction objective on their cross-correlation matrix C. Bottom-left: a one-class GMM is fitted on frozen embeddings of real images ( ZtrainZ_{train}) and scores each unseen test image ( ItestI_{test}) by −log⁡P(Ztest)-\log P(Z_{test}). Bottom-right: k-Means groups the frozen embeddings of an unlabeled real/AI-generated collection by image source.

In this paper we propose Forensic Twins, a Self-Supervised Residual Learning (SSRL) framework that decouples structural semantics from forensic noise. Figure 1 provides an overview of the proposed method and applications. Following the redundancy-reduction principle of BT (Zbontar et al., 2021), Forensic Twins is designed so that the low-level fingerprint of image formation is the only factor the objective can exploit. A frozen, pre-trained forensic residual extractor (Nguyen et al., 2025) suppresses macroscopic content while preserving high-frequency residuals, and two disjoint crops of these residuals, which break macro-spatial coherence, serve as the two views. A Vision Transformer (ViT) encodes both, and driving the cross-correlation matrix of their embeddings towards the identity enforces cross-view invariance while decorrelating feature dimensions. The dominant signal both crops still share is the stationary, microscopic trace that image formation spreads uniformly over the image plane.

Crucially, Forensic Twins is trained exclusively on real images. Generators leave fingerprints such as up-sampling artifacts and unnatural pixel-level correlations (Marra et al., 2019; Wang et al., 2023; Corvi et al., 2023a; Tan et al., 2024), but these are generator-specific and shift with every new architecture. Real images, in contrast, form a single, physically constrained class produced by the same family of acquisition and processing pipelines (e.g., sensors, color filter arrays, color corrections, etc.). Modeling only that class makes any departure from it, including generators that did not exist at training time, OOD by construction. As can be seen in Figure 1, we explore the potential of Forensic Twins on two downstream forensic tasks: i) AI-generated image detection, and ii) unsupervised clustering of image sources. In summary, the main contributions are:

• Forensic Twins architecture. We propose a novel SSRL architecture that mitigates the bias towards semantic representations present in standard SSL architectures. We showcase that applying a residual extractor along with spatially disjoint crops, favors the stationary micro-statistics of the image acquisition pipeline as the dominant signal the objective can exploit. Furthermore, Forensic Twins is trained exclusively on real images, using a lightweight encoder of 3.0M parameters. We release the code, weights and data splits for reproducible research.

• Proficiency at Downstream Forensic Tasks. We showcase the utility of Forensic Twins in two downstream forensic tasks: Detection of AI-Generated Images and Image Source

Clustering. For the detection task, a single GMM is fitted offline using only real image embeddings, and a test real/AI-generated image is flagged by its density under that model, achieving 97.99% mean AUC across 27 generative architectures. For image source clustering, a k-Means algorithm is fitted using the real/AI-generated image representations extracted using Forensic Twins. Our proposed Forensic Twins improves previous state-of-the-art zero-shot method by 6.13% in terms of accuracy.

References (58)

  • Dissecting the High-Frequency Bias in Convolutional Neural Networks
  • Blended Diffusion for Text-Driven Editing of Natural Images
  • A Unified Approach with Diffusion Models
  • Computer Science
  • Tuning-Free Generalized Image Morphing with Diffusion Model
  • Emerging Properties in Self-Supervised Vision Transformers
  • What Makes Fake Images Detectable? Understanding Properties That Generalize
  • TextDiffuser: Diffusion Models as Text Painters
  • Improved Baselines with Momentum Contrastive Learning (opens arXiv in a new tab)
  • Intriguing properties of synthetic images: From generative adversarial networks to diffusion models
  • On the Detection of Synthetic Images Generated by Diffusion Models
  • Raising the bar of ai-generated image detection with clip
  • ImageNet: A Large-Scale Hierarchical Image Database
  • Diffusion Models Beat GANs on Image Synthesis
  • Scaling Rectified Flow Transformers for High-Resolution Image Synthesis
  • Open Set Synthetic Image Source Attribution
  • Rich Models for Steganalysis of Digital Images
  • StyleShot: A Snapshot on Any Style
  • A Survey on Self-Supervised Learning: Algorithms, Applications, and Future Trends
  • TruFor: Leveraging All-Round Clues for Trustworthy Image Forgery Detection and Localization
  • OmniAID: Decoupling Semantics and Artifacts for Universal AI-Generated Image Detection in the Wild
  • Momentum Contrast for Unsupervised Visual Representation Learning
  • Any-resolution AI-Generated Image Detection by Spectral Learning
  • Progressive Growing of GANs for Improved Quality, Stability, and Variation
  • Supervised contrastive learning
  • Normalizing Flows: An Introduction and Review of Current Methods
  • Microsoft COCO: Common Objects in Context
  • on Multimedia Information Processing and Retrieval (MIPR), pp. 506–511
  • GANprintR: Improved Fakes and Evaluation of the State of the Art in Face Manipulation Detection
  • Forensic Self-Descriptions Are All You Need for Zero-Shot Detection, Open-Set Source Attribution, and Clustering of AI-Generated Images
  • GLIDE: Towards photorealistic image generation and editing with text-guided diffusion models
  • Towards Universal Fake Image Detectors that Generalize Across Generative Models
  • Transactions on Machine Learning Research Journal, 2024
  • Performance Comparison and Visualization of AI-Generated-Image Detection Methods
  • Scalable Diffusion Models with Transformers
  • Sdxl: Improving Latent Diffusion Models for High-Resolution Image Synthesis
  • Scaling Stylegan to Large Diverse Datasets
  • DINOv3
  • Deep Image Fingerprint: Towards Low Budget Synthetic Image Detection and Model Lineage Analysis
  • Roformer: Enhanced Transformer with Rotary Position Embedding
  • Learning on Gradients: Generalized Artifacts Representation for GAN-Generated Images Detection
  • Rethinking the Up-Sampling Operations in CNN-Based Generative Network for Generalizable Deepfake Detection
  • A Survey of Face Manipulation and Fake Detection
  • High-Frequency Component Helps Explain the Generalization of Convolutional Neural Networks
  • DIRE for Diffusion-Generated Image Detection
  • Early Convolutions Help Transformers See Better
  • Masked frequency modeling for self-supervised visual pre-training
  • Effort: Efficient Orthogonal Modeling for Generalizable AI-Generated Image Detection
  • Barlow Twins: Self-Supervised Learning via Redundancy Reduction
  • Unleashing the Capability of Diffusion Models for Image Morphing
  • Detecting Generated Images by Fitting Natural Image Distributions
  • A Unified Framework for High-Quality Text Synthesis in Arbitrary Images via Character-Aware Diffusion Models
  • GenImage: A Million-Scale Benchmark for Detecting AI-Generated Image
  • >Method</td><td rowspan=
  • Embeddings are $\ell_2$-normalised, and a $k$-nearest-neighbour classifier with cosine distance is fitted on half of the images of each class and evaluated on the other half
  • Our semantic accuracy is clearly above chance (39.03% against 14.29%), so the representation is not fully content-invariant
  • GFLOPs and latency start from an input tensor that is already decoded and already preprocessed by each method's own pipeline, so they isolate the detector from file I/O
  • We retrain the encoder on a single real source and fit the GMM on that same source alone, so the other source is never observed at any stage, and we then evaluate both real axes