Many industrial anomaly detectors never see a real defect during training. Instead they paste fake defects onto defect-free images and learn to undo them. The best-known example is DRÆM, which cuts random blob shapes out of Perlin noise (a smooth random pattern often used to generate natural-looking shapes) and fills them with textures borrowed from other datasets. The sizes of these fake defects are a hand-set hyperparameter. That setting was chosen on one benchmark, MVTec AD, and then reused everywhere. When the detector moves to a different dataset, with a different camera distance, resolution, or object footprint, the fake defects it trained on may be far larger or smaller than the real ones. The detector then learns to repair the wrong kind of damage.
We propose to measure this mismatch and to correct it without looking at a single target defect. The source dataset has annotated defect masks, which gives a real distribution of defect sizes. The target dataset has only normal images, but those images are enough to estimate how much larger or smaller things appear there than in the source. We use that scale ratio to carry the source defect-size distribution over to the target, and we draw the synthetic-defect sizes from the transported distribution. Because the correction is a single, monotone rescaling estimated from normal data, it has too few degrees of freedom to absorb real anomalies into "normal." That failure is the one that plagues learned feature alignment.
Core Claim
Part of the drop that reconstruction-based detectors suffer when moved between datasets is a scale mismatch, and it can be separated from other kinds of shift. The mismatch sits in the synthetic-defect generator and in the fixed input resolution. It can be removed by an alignment step that uses only normal images from the target.
The mechanism adapts Scale Match for Tiny Person Detection. That paper resizes source images so that the histogram of object sizes matches the target's, and it relies on labeled target boxes to build that histogram. Our setting has no target labels. What is new is the substitution: the target defect-size histogram is never observed. It is inferred from the source's measured defect sizes together with a scale ratio estimated from normal target images.
Written as a formula, let $p_s(a)$ be the distribution of defect areas $a$ (in pixels) from source ground-truth masks, and let $\hat r$ be the estimated linear scale ratio between target and source normal images. The transported target prior is
$$ \hat p_t(a) = \frac{1}{\hat r^{2}}\, p_s\!\left(\frac{a}{\hat r^{2}}\right), $$
which is simply the change of variables for areas under a linear rescaling by $\hat r$. We use it as a Monotone-Scale-Match-style mapping that keeps the ordering of defect sizes intact.
Research Program
The work has three pieces.
Scale estimation. We build and compare two estimators of $\hat r$ that use only normal images. The first measures object footprint: the foreground area fraction, obtained by thresholding a frozen backbone's feature saliency. The second measures texture period, using the dominant peak of the image autocorrelation. This one matters for texture categories, where there is no object outline to measure. We will test which estimator predicts the true scale ratio on controlled data, and whether the answer depends on the category type.
Alignment inside the detector. The transported prior $\hat p_t$ is used in two places. At training time, it sets the size distribution of the synthetic defects. Where DRÆM's pipeline uses a fixed Perlin frequency range, we choose, per target category, the Perlin frequency and threshold so that the areas of the generated masks match $\hat p_t$. At test time, $\hat r$ also chooses the input resolution, so that the receptive field of the reconstruction network lines up with the target footprint.
This two-sided use follows the lesson of An Analysis of Scale Invariance in Object Detection SNIP. That paper found that detectors do better when training concentrates on a matched range of scales than when filters are made to cover every scale. We do not import SNIP's gradient masking. We import only its diagnosis that matching scale beats covering all scales, and we test whether that diagnosis holds for reconstruction at all.
Cross-dataset validation as a diagnostic. Cross-dataset evaluations usually mix sensor, lighting, background, and scale shifts together, which makes failures hard to explain. We first build a scale-only shift: MVTec AD resampled at known factors, with the canvas padded or cropped so image size stays fixed. We then run real transfers from MVTec AD to VisA, Real-IAD, and MANTA-Tiny. Leave-one-dataset-out variants use each dataset in turn as the defect-size source.
Relation to prior work
Three prior papers motivate the gap.
- DRÆM pairs a reconstruction network with a discriminative network and trains both on Perlin-shaped fake defects. Its fake-defect sizes are arbitrary; ours are drawn from a measured distribution.
- SPot-the-Difference pre-trains representations with blended synthetic negatives and validates on both VisA and MVTec AD. It likewise never matches the size of its synthetic negatives to real defect sizes.
- MetaUAS aligns features between a normal prompt image and a query image across scales, using feature correlation. It reports that performance falls when the prompt and query differ in scale. That observation is further evidence that scale is an uncontrolled variable in cross-dataset anomaly detection.
Robust Distribution Alignment for Industrial Anomaly Detection under Distribution Shift constrains our design. It shows that aligning feature distributions toward an unlabeled target maps anomalous patches onto normal memory, which it calls "anomaly hijacking." It fixes this with a discretized optimal-transport assignment, but only for photometric corruptions and only for PatchCore memory banks. We deliberately avoid high-dimensional feature alignment and restrict the correction to one scalar per category.
SM+ supplies an instance-level alternative: it cuts out objects with segmentation masks and resizes each one. That route is unavailable here, because target defects have no masks. It also warns that pasting introduces seams, which a discriminative network can exploit as a shortcut.
An Empirical Study of the Generalization Ability of Lidar 3D Object Detectors to Unseen Domains is the most encouraging precedent. Simply resizing 3D anchor boxes to the target's average object size lifted detection from about 16 AP to 66 AP. We ask whether the 2D reconstruction setting hides a similarly cheap fix.
Baselines
Naive reference. The do-nothing baseline is DRÆM with its published MVTec hyperparameters and default input resolution, applied unchanged to each target dataset. On MVTec AD itself, DRÆM reports 98.0 image-level AUROC and 68.4 pixel-level AP, and 99.0 AUROC on DAGM. We found no reported result on Lacuna for DRÆM on VisA, Real-IAD, or MANTA-Tiny. We will therefore reproduce it on all three under identical training schedules.
Widened-range generator. This is the strongest simple competitor. It is DRÆM with the Perlin size range widened to cover every scale in all datasets, and it is the reconstruction analogue of multi-scale training. It receives the same number of training steps, and its range endpoints get the same tuning budget as our estimator's single free choice. Beating it means higher pixel AP and higher per-region overlap (PRO), a localization metric that averages overlap over each annotated defect region, on at least two of the three real transfers.
Global resize only. This ablation applies test-time resizing by $\hat r$ but leaves the synthetic-defect generator untouched. A matching ablation does the reverse. Together they isolate which half of the alignment carries the gain.
Oracle. The upper bound tunes the generator directly on target defect-mask sizes, as Scale Match would with target labels. It tells us how much of the reachable gain the normal-only estimate recovers.
Strongest existing shift-robust detector. This is PatchCore with RoDA. RoDA reports 91.34% mean AUROC on MVTec AD under level-5 corruptions and 71.00% on Real-IAD. We run it on the same scale-shifted and cross-dataset splits.
Class-agnostic reference. MetaUAS reports 95.3% pixel ROC on MVTec AD (MetaUAS). We evaluate it with and without $\hat r$-based query rescaling, which tests whether the estimator helps a detector that already claims to handle scale.
Why not just…?
Why not just widen the synthetic defect range, so every scale is covered? This is the real threat. The evidence that covering all scales dilutes filters comes from supervised detection in SNIP, not from reconstruction, and it may not carry over. The widened-range baseline settles the question directly. If it matches our method on pixel AP and PRO across the size-stratified bins, the scale-matching claim for the generator fails, and only the test-time half of the proposal survives.
Why not just resize target images so the object fills the frame, as the lidar anchor fix did? Industrial images mostly contain a single object. The objection that SM+ raises against image-level resizing, that one image can hold objects of very different sizes, is therefore weaker here, except on VisA's multi-instance categories. Resizing also blurs or discards the high-frequency detail that reconstruction residuals depend on. The global-resize-only ablation measures exactly this. We expect it to capture most of the gain on single-object categories and to fall short on textures and multi-instance scenes. If it does not fall short, we will report that the cheap fix suffices.
Why not just tune the generator on a handful of labeled target defects? When even five defects are available, that may well be the better choice. We will therefore also run a few-shot oracle using 1, 5, and 20 labeled target masks. Our method's claim is limited to the zero-anomaly regime. The comparison shows how many labeled defects the normal-only estimator is worth.
Why not just align features to the target, as domain adaptation does? RoDA reports that 46.4% of anomalous patches were misassigned to normal memory under standard alignment, and 16.1% even after its fix. A one-scalar correction cannot move individual patches at all. We will measure hijacking the same way for every method: the fraction of anomalous target patches that end up within normal-patch nearest-neighbor distance.
Proposed Experiments
Controlled scale sweep. The first decisive check resamples MVTec AD by factors from 0.25 to 2 and trains on the original scale. We then measure three things: how fast DRÆM's pixel AP and PRO decay with the factor, how accurately each estimator recovers the known factor, and how much of the decay the transported prior recovers.
Real transfers. The second check runs MVTec AD to VisA, Real-IAD, and MANTA-Tiny. MANTA-Tiny is chosen because its footprints are extreme. We report image AUROC, pixel AP, and PRO, each stratified by defect-area bin.
Falsifiable prediction. The method predicts that gains will concentrate in the categories where $\hat r$ is far from 1 and in the defect-size bins the default generator under-samples. Gains spread evenly across all categories would point to a regularization effect, not scale alignment.
Estimator error versus gain. Across categories we will correlate the error in $\hat r$, measured against oracle mask statistics, with the gain the method delivers. A null correlation would falsify the proposed mechanism even if average scores improve.
References
- Scale Match for Tiny Person Detection
- An Analysis of Scale Invariance in Object Detection SNIP
- DRÆM - A discriminatively trained reconstruction embedding for surface anomaly detection
- SPot-the-Difference Self-supervised Pre-training for Anomaly Detection and Segmentation
- MetaUAS: Universal Anomaly Segmentation with One-Prompt Meta-Learning
- Robust Distribution Alignment for Industrial Anomaly Detection under Distribution Shift
- SM+: Refined Scale Match for Tiny Person Detection
- An Empirical Study of the Generalization Ability of Lidar 3D Object Detectors to Unseen Domains