Post-hoc Selective Classification for Reliable Synthetic Image Detection

Kaixiang Zheng, Jacob H Seidman

TL;DR

Synthetic image detectors look like geniuses in the lab, but their accuracy tanks in the real world when images get blurry, compressed, or come from brand-new AI generators. Worse yet, when you try to let these detectors say "I don't know" on hard cases, their built-in confidence scores can become completely inverted—confidently keeping their worst mistakes and throwing away right answers. This paper introduces ReSIDe, a lightweight, plug-and-play wrapper that mines a detector’s hidden layers to restore sanity to its confidence estimates without retraining the model.

What Problem Does This Paper Address?

Deep neural networks trained to spot AI-generated images—Synthetic Image Detectors (SIDs)—easily achieve near-perfect accuracy on clean, familiar test sets. Yet in deployment, they run headfirst into covariate shifts: real-world messiness like JPEG compression, Gaussian blur, low resolution, adversarial tweaks, or images created by unseen generators. Under these shifts, detection error rates often degrade to ~50% (essentially a coin flip).

To prevent costly mistakes, engineers use Selective Classification (SC), which gives a model the option to abstain when its confidence falls below a threshold. We measure SC success using the Area Under the Risk-Coverage Curve (AURC)—lower is better, meaning low error rates across high proportions of accepted data.

For practical reasons, we want post-hoc SC, meaning we freeze the pretrained detector and just compute a Confidence Score Function (CSF) from its final output logits (like Maximum Softmax Probability, or MSP). However, the authors uncover a nasty surprise: under covariate shifts, standard logit-based confidence scores break down pathologically.

Figure 2: (a)-(f): RC curves for MSP evaluated using ResNet50 on datasets with different covariate shifts. (g)-(h): RC curves for MSP under the mixture distribution, evaluated using ResNet50 and Swin-T, respectively.

Look at subplot (a) Blur above: as you raise the confidence threshold to be more selective (moving right to left toward lower coverage), the error rate (Risk) shoots up toward 1.0! The model is systematically more confident when it is wrong than when it is right.

Methods

To fix this broken compass without retraining the underlying detector, the authors propose ReSIDe (Reliable Synthetic Image Detection), which relies on two clever ideas:

  1. Unsupervised Linear Probing (ULP) for Intermediate Logits: A network's final logits can be viewed geometrically as how closely a sample's final features match learned class templates (centroids). The authors extend this to every hidden layer. Taking clean training images, they run spherical $k$-means clustering on each layer's feature vectors to find natural centroids. For a new test image, its cosine similarity to a layer's centroids acts as "generalized logits" for that layer. Standard confidence functions (like MSP or MaxLogit) can now be applied at every depth of the network, extracting $L+1$ layerwise confidence scores instead of just one.
  2. Preference Optimization for Score Aggregation: Now we need to blend those $L+1$ scores into a single number using a simple linear weighted sum—amounting to just tens of trainable parameters. Using a hold-out validation set containing shifted data, the authors optimize these weights via a pairwise contrast loss (inspired by Bradley–Terry preference models, similar to RLHF). It explicitly pushes correctly classified samples to have higher combined scores than misclassified ones. Crucially, they mathematically prove that minimizing this loss directly lowers an upper bound on the AURC.
Figure 1: Illustration of the overall ReSIDe framework.

Datasets

The experiments curate training, validation, and test splits from GenImage, a massive benchmark of over 2.6 million real (ImageNet-1K) and synthetic images across eight generators.

  • Training: Real images + ADM and BigGAN across 50 semantic classes.
  • Testing: Seven distinct splits—In-Distribution (ID) plus six isolated covariate shifts: Blur, Unseen Semantic Classes (950 new classes), Low Resolution, FGSM (adversarial attacks), JPEG Compression, and Unseen Generators (Midjourney, Wukong, Stable Diffusion v1.4/v1.5).
  • Validation: Importantly, to avoid cheating, the validation sets used to tune the aggregation weights use different shift parameters than the test sets (e.g., unseen validation generators are GLIDE and VQDM, not Midjourney or Stable Diffusion). They also note extended evaluations on the recent EvalGen benchmark in the appendix.

Key Insights and Ideas

  • Final-layer tunnel vision: Even when a detector's final output layer is completely fooled and overconfident under distribution shifts, its intermediate hidden layers still retain healthy geometric signals that distinguish familiar patterns from anomalies.
  • Flipping the inverted distribution: On blurry images, baseline confidence distributions show misclassified images clustering at higher confidence values than correct ones. ReSIDe literally flips these distributions back into the proper order.
  • Better together, and orthogonal to other fixes: While picking the single best intermediate layer already beats the final layer, linearly combining all layers drops AURC by up to another 22.79%. Furthermore, ReSIDe stacks cleanly on top of existing logit-normalization tricks like pNorm for compounding gains.

Key Results

Tested on both CNN (ResNet50) and Vision Transformer (Swin-T) backbones across six different logit-based CSFs:

  • Individual Shifts: ReSIDe slashes AURC by up to 69.55% (ResNet50 with MaxLogit under Blur, dropping AURC from a worse-than-random 0.7271 down to 0.2214).
  • Realistic Mixture Distribution: When all seven test distributions (ID + 6 shifts) are mixed equally to simulate wild deployment, baseline CSFs hover near random-guessing AURCs (~0.356 for ResNet50; ~0.335 for Swin-T). ReSIDe cuts AURC across the board by up to 44.88% (bringing Swin-T down to 0.1845).
  • Stacking with pNorm: Combining ReSIDe with pNorm yields up to a 44.91% further AURC reduction over pNorm alone.

Limitations and Future Work

The authors candidly note three practical constraints:

  1. DNN-only: Because ULP relies on hidden-layer representations, the full pipeline only works on deep neural networks (though the preference-based score aggregation could work on any model outputting multiple confidence signals).
  2. Validation set dependence: Because aggregation weights are learned on a hold-out validation set, practitioners must ensure their validation shifts are diverse enough not to overfit to one specific type of corruption.
  3. Training data access: Computing the spherical $k$-means centroids requires access to samples from the original training distribution; without them, one would have to approximate the training data, potentially introducing errors.

Summary updated

Abstract

As synthetic images become increasingly realistic, reliable synthetic image detection techniques are of pressing need to prevent their misuse. Despite satisfactory in-distribution performance, deep neural network-based synthetic image detectors (SIDs) lack reliability in deployment and often fail in the presence of common covariate shifts, resulting in poor detection accuracy. To avoid the risk caused by potential errors, we adopt a selective classification (SC) strategy by allowing SIDs to abstain from making low confidence predictions. For practicality, we focus on post-hoc methods which perform confidence estimation on a given SID without retraining. However, we show that conventional logit-based confidence score functions (CSFs) exhibit pathological behavior under covariate shifts, leading to SC performance close to or even worse than random guessing. To address this, we propose a simple yet effective SC framework for **Re**liable **S**ynthetic **I**mage **De**tection (ReSIDe). First, we generalize the notion of logits to an SID's intermediate layers from a centroid matching perspective, extending the use of logit-based CSFs to any layer of an SID. Then, we introduce a preference optimization algorithm that aggregates confidence scores extracted from different layers to a final confidence estimate by minimizing an upper bound of the area under the risk-coverage curve (AURC). Extensive experimental results show that ReSIDe significantly boosts the SC performance of various logit-based CSFs under common covariate shifts, achieving up to 69.55% AURC reduction.
BibTeX
@inproceedings{zheng2026post,
  author = {Kaixiang Zheng and Jacob H Seidman},
  title = {{Post-hoc Selective Classification for Reliable Synthetic Image Detection}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2026},
  url = {https://openreview.net/forum?id=WYncw2up3x},
}
Figure