Transporting Synthetic Anomalies Across Domain Shift

Industrial anomaly detectors learn what "normal" looks like from defect-free images. The best of them also train on fake defects ("synthetic anomalies") so that the model sees something on the other side of the boundary. These systems break when the camera, lighting or sensor changes after deployment. A benign change in appearance looks like a defect, and false alarms spike. The obvious fix is to collect normal images from the new setting and rebuild everything, including the fake defects. That rebuild is expensive: realistic defect generators based on diffusion models, which produce images by gradually denoising random noise, can require hundreds of thousands of rendered images. It is also often impossible, because a new production line supplies only a handful of unlabeled images at first.

We propose a cheaper route. Learn a small map that sends the detector's internal features for source-domain normal images onto the features of a few unlabeled target-domain images. Then push the source's existing synthetic defect features through the same map, and retrain only the final scoring head. The whole approach rests on one testable bet. A map fitted only on normal data should carry a defect's offset from normal into the new domain intact, so defects never need to be regenerated in the new domain. If the bet holds, adapting to a new domain costs minutes on a single GPU, renders no new images, and adds no test-time latency.

Core Claim

Consider a feature-space anomaly detector: a frozen pretrained image encoder, a light adapter, and a small classifier that separates normal features from synthetic-anomaly features. For such a detector, an unpaired translation map between source and target normal features can be fitted with partial optimal transport. Optimal transport is a way of matching two sets of points so that the total movement is small; the "partial" version is allowed to leave some points unmatched. This map transfers the source's synthetic anomalies to the target domain well enough to beat the practical alternatives in the regime of few target images. Those alternatives are retraining on the target images, re-estimating normalization statistics, translating test images back to the source, and augmenting with generic corruptions.

The claim is falsifiable in three ways. It fails if a per-channel affine map (a mean and variance match) does as well as the nonlinear map. It fails if retraining from scratch on the target images catches up once there are a few dozen of them. It fails if generating fresh noise anomalies around mapped normals works as well as transporting the source anomalies themselves.

Where This Sits

The synthetic-anomaly work we build on assumes the test domain matches training. SimpleNet adds Gaussian noise to pretrained features and trains a discriminator, reaching 99.6% image AUROC on MVTec AD at 77 FPS. PBAS instead synthesizes feature-level anomalies along rays toward a learned boundary (99.8% I-AUROC, 75 FPS). RealNet renders realistic defects with a strength-controlled diffusion model, at the cost of an offline 360,000-image synthetic set. These papers supply our anomaly sources and our base architecture. What we add is the ability to move their anomalies into a shifted domain without rerunning them. RealNet's expense is exactly what makes reuse valuable.

Two papers motivate the problem by showing that these detectors fail under shift. ROADS reports that SimpleNet falls to 72.0% P-AUPRO under defocus blur on VisA. GNL documents the false alarms caused when benign shift is confused with defects.

The existing shift-robust detectors take different routes. GNL trains with AugMix plus a cosine loss that preserves normality, then at test time matches each input's feature distribution to a random training sample, at roughly 2.8x training overhead. ROADS trains an instance-normalization-based domain adapter on heavily augmented images and reads a style code from each test image. Everything to the Synthetic purifies every test image with a diffusion model into a shared synthetic domain. All three either never look at the target domain, relying on generic corruptions, or pay a per-image cost at test time. None moves the anomalies into the target domain. We do both of those things differently: we use a few target images, and we pay nothing per test image.

The closest prior use of unpaired translation for defects is CycleGAN on periodic textures. That work maps defective textures to clean templates and subtracts. It is limited to periodic patterns, needs two generators and two discriminators, and ignores domain shift. This line of work constrains our design, because pixel-space translation is known to erase or hallucinate fine structure. Context-Aware Optimal Transport addresses a related problem by computing transport cost on deep features rather than pixels. We take from it the method choice of doing translation in feature space with optimal transport. We take the partial-transport idea from MADPOT, which relaxes mass conservation so that background patches are not forced onto anomaly prompts. We repurpose it so that unlabeled defects hidden in the target sample are left unmatched instead of being pulled into the normal map.

Research Program

Let $X_s$ be frozen-encoder patch features of the many source normal images. Let $X_t$ be patch features of $k$ unlabeled target images, where $k$ ranges from 5 to 200 and a small fraction may be defective. Let $A_s$ be source synthetic-anomaly features from any generator.

The first step computes an entropic partial optimal transport plan $\pi$ between minibatches of $X_s$ and $X_t$ that moves only a fraction $m<1$ of the mass. The second step fits a small residual network $T(x)=x+g(x)$ to the barycentric targets of that plan, with a penalty that keeps $g$ smooth and small:

$$\min_{g}\ \sum_{i} \Big\| x_i + g(x_i) - \tfrac{\sum_j \pi_{ij} y_j}{\sum_j \pi_{ij}} \Big\|^2 + \lambda\, \mathbb{E}_x \|\nabla g(x)\|_F^2 ,$$

Here $x_i\in X_s$ and $y_j\in X_t$ are features, the sum runs over source points that received mass, and $\lambda$ controls smoothness. Smoothness is what makes transfer to anomalies plausible. A defect feature $a = x + \delta$ lies near its normal counterpart $x$, and a smooth $T$ gives $T(a)\approx T(x) + J_T(x)\,\delta$, where $J_T(x)$ is the Jacobian of $T$ at $x$. The defect offset is therefore carried along and locally rotated and scaled with the domain. Setting $g$ to a per-channel affine function recovers mean/variance matching exactly, which is our main ablation.

The third step retrains only the adapter and scoring head. The normal class is $X_t$ together with $T(X_s)$; the anomaly class is $T(A_s)$. The encoder and test-time pipeline are unchanged, so inference speed stays at the base detector's.

On the analysis side, we measure directly whether defect offsets survive transport. We apply known image corruptions to real annotated defect images, which yields paired ground truth for evaluation only. We then compare $T(a)-T(x)$ with the true shifted offset by cosine similarity and norm ratio, broken down by corruption type and anomaly generator. This tells us when the bet holds, rather than only whether detection accuracy moves.

We report cost as wall-clock adaptation time, number of images rendered (zero for our method), GPU memory, and test FPS.

Baselines

The naive reference is the source-trained detector (SimpleNet and PBAS) applied unchanged to target data. It fixes the size of the problem, and ROADS's reported 72.0% P-AUPRO for SimpleNet under VisA defocus blur anchors this floor.

The strongest existing method is ROADS. It reports 93.2% I-AUROC on MVTec-AD under Gaussian noise, and in the same paper GNL scores 71.1%. ROADS also reports 89.55% P-AUPRO on VisA under defocus blur. ROADS sees no target images, so for fairness we run it twice. The first run follows its original protocol. The second fine-tunes it on the same $k$ target images with its own losses, using the same backbone family and the same tuning budget of hyperparameter trials and GPU hours as our method. Beating it means higher P-AUPRO and I-AUROC than the $k$-image ROADS variant at $k\le 50$ on shifts outside its augmentation family, without losing more than a point on the corruptions it was designed for.

GNL is run from its protocol, and additionally with its test-time feature matching aimed at our $k$ target images instead of random source samples. There is no reported result on Lacuna for GNL on VisA or MPDD, so we will produce those ourselves.

The same-information baselines are the most important, because they use exactly our $k$ target images. The first retrains SimpleNet/PBAS on the $k$ images alone. The second retrains on the pooled source and target normals without transport. The third re-estimates normalization statistics from the $k$ images, following The Norm Must Go On and, for tiny batches, MemBN. The fourth is the obvious idea: an image-space CycleGAN trained between source and target normals, then used to translate RealNet-style defect images, followed by retraining.

Three ablations isolate the key ingredient. The first restricts $T$ to affine maps. The second transports only normals and draws fresh Gaussian or PBAS anomalies around $T(X_s)$, which tests whether transporting the anomalies matters. The third replaces partial transport with full transport when the target sample is 5–10% contaminated.

Why not just…?

Why not just retrain the detector on the target normal images? With enough target images this should win, and we expect it to. Our claim concerns the few-image regime and the cost of reproducing realistic anomalies. The $k$-sweep settles this: we predict our method leads for $k\le 50$ and the curves meet by around 200. If they meet at 20, the method has no practical niche and we will say so.

Why not just re-estimate normalization statistics or match channel means and variances? This is the most serious threat for pointwise corruptions such as noise and blur, where an affine feature correction may capture most of the shift. MemBN also notes that such statistics are unstable at batch sizes of one or two, which is typical on inspection lines. The affine ablation answers the question directly. If affine matching equals the nonlinear map on every shift, the contribution reduces to "retrain the head on affinely shifted anomalies", which is still useful but narrower. We expect the nonlinear map to matter for illumination color casts, viewpoint and scale changes, and compound shifts.

Why not just translate test images back into the source domain? Diffusion purification (Everything to the Synthetic) and GNL's feature matching both put a cost on every test image. Pixel translation also risks erasing the small defects we need to find, as the retinal optimal-transport work warns for lesions and vessels. We measure localization loss on small defects and FPS for these methods against our method, which adds no per-image cost.

Why not just augment with generic corruptions, as ROADS does? For shifts inside the augmentation family, ROADS may match us without seeing any target data, which is a genuine advantage. Our argument is limited to shifts the augmentations do not model, so the evaluation deliberately separates the two families.

Proposed Experiments

The benchmarks are MVTec AD and VisA under the noise and blur corruption protocols used by ROADS and GNL. To these we add structured shifts we construct: color-temperature casts, uneven illumination, viewpoint crops and rescaling, and compound sensor noise plus compression. MPDD, whose varied angles and illumination make it natural, is split by acquisition condition where such a split can be built from its images. Metrics are I-AUROC, P-AUROC and P-AUPRO, false-positive rate at 95% recall on target normals, adaptation time, and FPS. Anomaly sources are Gaussian feature noise, PBAS rays, and RealNet-style diffusion defects, so we can test whether costly realistic anomalies transfer better than cheap ones.

The decisive checks are four. The first is the $k$-sweep against target-only retraining. The second is the affine-versus-nonlinear comparison, split by shift type. The third is transport-anomalies versus fresh-anomalies-around-mapped-normals. The fourth is the offset-preservation measurement: if the cosine similarity between transported and true defect offsets is low while detection still improves, the gain comes from better normals rather than transported anomalies, and the claim must be restated.