Reconstruction-based anomaly detectors have a practical gap. These are models trained only on normal images, which redraw a test image as a "normal" version and flag the places where input and redrawing differ. They are usually scored by area under the ROC curve, a measure that averages over every possible threshold. A factory line or a radiology workflow, by contrast, must pick one threshold, and nobody can say how many of the regions it flags will be false alarms. Recent work fixes part of this with selective inference: statistical tests that account for the fact that a region was tested because it looked anomalous. These tests are exact, but they only work for small networks built from piecewise-linear pieces such as ReLU autoencoders. They cannot handle the diffusion models that now lead the benchmarks.
We propose a different route. Treat the entire detector as a black box: network, residual map, thresholding, connected-component extraction and region scoring. Run that same pipeline on a held-out set of normal images, and compare a test region's score to the scores that the identical selection procedure produces on normal data. Because selection is replayed on the calibration images rather than modeled analytically, the resulting p-values remain valid for diffusion, GAN, or discriminative detectors. They also test the null hypothesis practitioners actually care about: "this region is no stranger than what the detector finds in genuinely normal images." The standard selective-inference null is narrower: "this residual is Gaussian noise around a fixed signal."
Core Claim
Selection-aware calibration against a nominal reference set gives finite-sample control of false alarms at the image level, and approximate control of the region-level false discovery rate (FDR, the expected fraction of flagged regions that are not real defects), for any reconstruction detector. The claim has two parts. First, it controls false alarms on real normal images better than Gaussian-noise selective inference, because real normal images carry structured deviations that the detector reconstructs imperfectly, such as anatomical variation, texture and edge misalignment, and illumination. Second, it turns the benchmark question from "what is your AUROC" into "how many true defects do you recover at a certified FDR of 0.1." On that question the ranking between detectors such as GLAD and DRÆM may differ from their AUROC ranking.
The method is simple. For a detector $D$ that maps an image to a set of candidate regions, each region $R$ gets a score $T(R)$, for example its mean residual. Collect $D$'s regions on $n$ calibration normal images that were not used for training. Define the image-level statistic $M(x)=\max_{R \in D(x)} T(R)$ and its p-value
$$p(x) = \frac{1 + \#\{i \le n : M(x_i) \ge M(x)\}}{n+1},$$
which is valid whenever the test image and calibration images are exchangeable under the null. That holds because the maximum over selected regions is computed identically on both sides, so the selection step is already inside the null distribution. For individual regions, each test region is ranked against the pooled calibration regions that fall in the same stratum of size and location:
$$p(R) = \frac{1 + \#\{R' \in \mathcal{C}_{s(R)} : T(R') \ge T(R)\}}{1 + |\mathcal{C}_{s(R)}|}.$$
Here $\mathcal{C}_{s}$ is the set of calibration regions in stratum $s$. The Benjamini–Hochberg procedure, a standard rule for controlling the false discovery rate across many tests, is then applied within and across images.
The image-level guarantee is exact. The region-level guarantee is not automatic. Normal-looking regions inside a defective image may not be exchangeable with regions from fully normal images, because a large defect can disturb the reconstruction elsewhere. Measuring how far this assumption fails is a central empirical question of the project, not something we assume away.
Relation to Prior Work
The motivating evidence comes from three selective-inference papers that showed how badly naive testing fails once selection is ignored. Statistical Test for Anomaly Detections by Variational Auto-Encoders derives exact truncated-normal p-values for regions flagged by ReLU VAEs. It reports that on a healthy brain MRI, a naive test returns $p=0.000$ while the selective test returns $p=0.668$. Quantifying Statistical Significance of Deep Nearest Neighbor Anomaly Detection via Selective Inference does the same for distances in a deep feature space and bounds Type I error at 0.05 on MVTec AD. Statistical Test for Saliency Maps of Graph Neural Networks via Selective Inference reports naive false-positive rates near 80%. All three depend on piecewise linearity and additive Gaussian noise with known or estimated variance. Our proposal drops both requirements. In exchange it gives up per-image exactness and requires a nominal calibration set.
CAD-DA shows a constraint we must respect: Bonferroni correction pushes power to near zero, so any correction for multiplicity must adapt to the data rather than rely on the worst case.
The method is applied to existing detectors, which we do not modify. DRÆM combines a reconstruction network with a learned discriminative segmenter and outputs a sigmoid map with no error guarantee. GLAD adapts the number of diffusion denoising steps per input. That input-dependent behavior is exactly what makes analytic selective inference impossible, and replaying the pipeline is unaffected by it. Denoising Diffusion Models for Anomaly Localization in Medical Images offers sampling-variance maps as uncertainty, without hypothesis-testing semantics. MVTec AD supplies the benchmark and names the "thresholding trap": with no anomalies available for validation, operating thresholds cannot be set. Our method addresses this trap directly, because the threshold follows from a chosen FDR rather than from labeled anomalies.
The knockoff approach of Statistically Significant Concept-based Explanation of Image Classifiers via Model Knockoffs controls FDR over discrete concepts in supervised classifiers. It needs a generative model of knockoffs, which our approach avoids, and it does not address spatial localization.
Research Program
The work has three parts.
The first is the calibration machinery. It covers image-level max-statistic p-values; stratified region p-values with strata defined by area quantile and, for aligned object categories, a coarse spatial grid; and Benjamini–Hochberg control across regions. We will also study p-value resolution. With $n$ calibration images, the smallest image-level p-value is $1/(n+1)$, so MVTec's few hundred normal images per category limit power at strict levels. Pooling regions across images helps at the region level. We will report how power scales with $n$ by subsampling the calibration set.
The second part is a stress test of the region-level exchangeability assumption. For defective images with ground-truth masks, we count discoveries that do not overlap any annotated defect, which gives the empirical false discovery proportion. We then check whether it stays below the target $q$. A stricter variant calibrates only against regions that defect-free reference images produce at the same spatial location. If pooled calibration leaks false discoveries near large defects, we will test a guard band that excludes a dilated neighborhood around higher-ranked discoveries. We will report the resulting loss of power.
The third part reruns the benchmark comparison. For GLAD, DRÆM, a ReLU VAE, and a deep-kNN detector, all wrapped identically, we report defect-region recall at FDR $q\in\{0.05, 0.1, 0.2\}$, together with image-level power at $\alpha=0.05$.
Baselines
The do-nothing reference is the detector's own operating point: DRÆM's sigmoid map at 0.5, and GLAD's residual map at the threshold its code uses, run from hyao1/GLAD and zhangzjn/ADer. We report its realized false discovery proportion to show the size of the problem. This is the baseline that matches how these systems are deployed. Beating it means a lower realized FDR at comparable recall.
The heuristic calibration baseline thresholds each pixel at the 99th percentile, or $\mu+3\sigma$, of residuals on the same calibration images, then reports connected components. It uses exactly our calibration data. It differs only in calibrating pixels rather than the selected-region statistic, so it doubles as the key ablation that isolates the selection-aware ingredient. We expect it to over-discover because it ignores the max over regions. Beating it means realized FDR at or below $q$ where it exceeds $q$.
The naive Gaussian test computes z-scores of region means against nominal residual mean and variance. The cited papers already show it fails, and it is included only to reproduce that failure on diffusion residuals. Bonferroni over regions is the conservative reference. Given CAD-DA's near-zero power, beating it means substantially higher recall at the same nominal level.
The strongest competitor on validity is exact selective inference, the VAE-AD test, which applies only to the ReLU VAE. We will run it on that VAE with identical training data. On error control, the file gives no number on real data beyond the single healthy-scan example ($p_{selective}=0.668$). On its synthetic and MRI settings, Type I error is reported as controlled at 0.05. We will measure its false-rejection rate across all of MVTec's held-out normal test images and across healthy MRI scans, where structured, non-Gaussian residuals are expected. Our method beats it if it holds 0.05 there while selective inference does not, or if it matches it with higher power. If selective inference also holds 0.05 with more power on the VAE, we report that honestly. Our remaining advantage would then be generality to other architectures, not superiority.
The deep-kNN test serves the same role on MVTec, where it reports Type I error at or below 0.05.
The strongest detection systems are GLAD (image AUROC 99.3%, pixel AUROC 98.6% on MVTec AD) and DRÆM (image AUROC 98.0, pixel AP 68.4). No reported result was found on Lacuna for defect recall at a fixed certified FDR for any of them, so that metric is new. Our wrapper does not change their AUROC. Success here means delivering error control at a cost in recall that we measure and report.
All methods share training splits, calibration images, region-extraction code, and compute. The detectors are trained once and never retuned for the statistical wrappers.
Why not just…?
Why not just use image-level conformal p-values with Benjamini–Hochberg and stop there? Conformal p-values rank a test score against scores from held-out normal data. This is a real threat for the image-level question, and our image-level test is essentially that method, so we claim no novelty for it. What image-level calibration cannot answer is where the defect is. Localization is the reason to use reconstruction methods at all, and it is where the thresholding trap actually hurts. The project's contribution stands or falls on the region-level experiments. If the false discovery proportion among non-overlapping regions cannot be kept below $q$ even with guard bands, we will say that only image-level guarantees are achievable for black-box detectors.
Why not just use exact selective inference on a better piecewise-linear model? It would give per-image exactness, but it requires piecewise linearity and Gaussian noise. That excludes GLAD's adaptive diffusion and DRÆM's learned segmenter, which are the detectors that actually perform well. The head-to-head test on the ReLU VAE checks whether its null also fails on real normal images. If it does not, the remaining case for our method is generality alone.
Why not just threshold residuals at a nominal percentile? That is the pixel-calibration ablation above. It ignores the fact that reporting the largest of many regions inflates extremes. The MVTec AD baselines show how poorly empirical thresholds localize: region overlap was 0.05 on cable despite 0.86 AUROC. Our experiment measures directly how much FDR this heuristic leaks.
Why not just use diffusion sampling-variance maps? As the diffusion localization paper notes, variance measures how uncertain the generator is, not whether the input differs significantly from normal. It also multiplies inference cost by the number of samples. We will include variance-normalized residuals as an alternative region statistic $T$ inside our calibration. Variance thus becomes a possible way to gain power rather than a competing guarantee.
Proposed Experiments
The datasets are MVTec AD (15 categories, pixel masks), MPDD and PCB-Bank, chosen to stress pose variation and complex texture, and the 1,880-scan brain MRI set used by the VAE-AD test. For each category we split normal training images into training and calibration sets, sweeping the calibration size from 25 to the maximum available.
Three checks are decisive. The first is image-level Type I error on all held-out normal test images, which must stay at or below $\alpha=0.05$ for every detector. The second is the realized region-level false discovery proportion on defective images, measured against ground-truth masks, which must stay at or below $q$ for pooled, location-stratified and guard-band variants. The third is defect-region recall at $q=0.1$, compared across GLAD, DRÆM, the VAE and deep-kNN, against those detectors' AUROC ordering.
A negative result on the second check, region FDR exceeding $q$ near large defects, would be informative. It would show that region-level guarantees for black-box reconstruction detectors require something beyond nominal calibration. The third check tests whether certified-FDR recall reorders detectors. If it does, that is evidence the community's AUROC-centered leaderboards hide the property deployments depend on.
References
- Statistical Test for Anomaly Detections by Variational Auto-Encoders
- Quantifying Statistical Significance of Deep Nearest Neighbor Anomaly Detection via Selective Inference
- Statistical Test for Saliency Maps of Graph Neural Networks via Selective Inference
- CAD-DA: Controllable Anomaly Detection after Domain Adaptation by Statistical Inference
- DRÆM - A discriminatively trained reconstruction embedding for surface anomaly detection
- GLAD: Towards Better Reconstruction with Global and Local Adaptive Diffusion Models for Unsupervised Anomaly Detection
- Denoising Diffusion Models for Anomaly Localization in Medical Images
- MVTec AD - A Comprehensive Real-World Dataset for Unsupervised Anomaly Detection
- Statistically Significant Concept-based Explanation of Image Classifiers via Model Knockoffs