Factories increasingly train one anomaly detector to cover many product types. This detector is a reconstruction model: it learns to redraw only defect-free ("normal") images, so wherever it fails to redraw a new image, that region is flagged as a defect. A detector trained on dozens of product categories is then installed on a single line that makes only a few of them. That line has its own cameras and lighting, and its unlabeled images include some real defects. We argue that the categories absent from the line do active harm. Their normal appearance gives the model extra ways to redraw a defect as something plausible: a scratch on wood can be "repaired" with grid or carpet texture. The defect then leaves no trace in the difference between input and reconstruction.
This mirrors negative transfer in partial domain adaptation. There, a classifier adapted from a large source label set to a target containing only a subset of those classes is corrupted by the classes that are not present. The fix in that literature is to estimate which source classes appear in the unlabeled target and down-weight the rest. We propose to bring that class-importance weighting into reconstruction-based anomaly detection, and to use it for a different purpose. It would not mainly steer feature alignment. Instead, it would switch off the reconstruction pathways of absent classes, so the model has less capacity to redraw defects, and it would restrict style adaptation to the classes that are actually present. The class weights themselves are estimated from class-conditional reconstruction residuals. These residuals are computed in a way that is insensitive both to localized defects and to the camera and lighting shift of the new line.
Core Claim
The main claim has two parts. First, in a class-conditioned multi-class reconstructor, removing absent classes at deployment improves defect detection and localization on the target subset, even with no domain shift at all. This happens because those classes provide cross-class reconstruction routes for defects. Second, the set of present classes can be recovered from unlabeled, defect-contaminated, domain-shifted target images using a trimmed class-conditional residual.
We define that residual as follows. For a target image $x$ and a source class $c$, let $r_c(x)$ be the mean reconstruction residual over the $(1-q)$ fraction of image patches with the smallest residual when the decoder is conditioned on class $c$. Here $q$ is an upper bound on the fraction of the image a defect occupies. Soft class assignments and class weights are then
$$ p(c \mid x) = \frac{\exp(-r_c(x)/\tau)}{\sum_{c'} \exp(-r_{c'}(x)/\tau)}, \qquad w_c = \frac{1}{N}\sum_{i=1}^{N} p(c \mid x_i), $$
where $\tau$ is a temperature and $N$ is the number of unlabeled target images.
The design rests on three properties of this residual. A localized defect only raises the top-$q$ patches, which the trimming discards. A global class mismatch raises every patch. A camera or lighting shift raises the residual under all classes by roughly the same amount, so to first order it cancels out of the softmax.
Once the weights are computed, they are binarized with the between-cluster variance (Otsu) threshold from Choudhuri et al.. That work clusters target class probabilities and cuts outlier classes to zero for classification. We reuse the threshold but feed it reconstruction-derived evidence. Classes below the threshold have their conditioning tokens removed from the decoder.
Research Program
Source model. On the source side we train a class-conditioned reconstructor on labeled normal images from MVTec AD and VisA together, 27 categories in all. The conditioning follows the class-aware prompt tokens of ROADS, a reverse-distillation detector with class prompts and instance-normalization (AdaIN) domain adapters. We will also try the class-aware queries of MINT-AD, which reduces inter-class interference using known class labels. Both prior methods assume class labels at test time and a fixed category set. They supply our architecture and motivate the interference concern, but neither asks which classes to drop when the label set changes at deployment.
Target adaptation. On the target side we run three steps on the unlabeled pool. First, we compute the weights $w_c$ and prune the absent classes. Second, we adapt only the lightweight style adapters on target images, routing each image to its most likely surviving class. Third, during that adaptation we mask out each image's top-$q$ residual patches so that real defects are not learned as normal.
This patch-level masking is the main departure from Importance Weighted Adversarial Discriminative Transfer for Anomaly Detection. That paper weights whole target images by autoencoder reconstruction error, in a single-class, two-stage pipeline. It has no notion of absent source classes, and it cannot tell a defect apart from a class mismatch or a domain shift, since all three raise error. Our method separates these three causes by their spatial pattern, which is the tension identified in Gap 2 of the file.
Analyses. We will measure how well $w_c$ recovers the true class set as three factors vary: the overlap ratio, the contamination rate, and the severity of the domain shift. We will test whether one round of re-estimation after adaptation helps, or instead feeds back its own errors. That feedback loop is a known failure of prediction-averaged weights in Deep Residual Correction Network for Partial Domain Adaptation. We will also map, for each target class, which pruned source classes had been "absorbing" its defects.
Baselines
The first reference point is the unadapted unified model: the 27-class source model deployed on the target line with all classes active. It is the do-nothing option a practitioner would actually try. The evidence says it degrades under shift. ROADS reports competitors falling to 71.1% image-level AUROC on MVTec AD under Gaussian noise, and ADNet reports a 14–34% gap when models trained on its Industry domain are tested on other domains.
The strongest existing method is ROADS itself, adapted with its own domain adapters on the full unlabeled target pool and with every class kept. It is the competitor most directly built for multi-class reconstruction under shift. It reports 93.2% image-level AUROC on MVTec AD under Gaussian noise and 98.83% in distribution. We will retrain it on our merged MVTec AD and VisA source with the same backbone, adapter size, number of target adaptation steps and hyperparameter search budget as our method. Beating it means higher image-level AUROC and higher region-overlap localization (PRO / AUPRO) on the target subset, averaged over target subsets and seeds, at contamination rates of 10% and above. Equal scores at 0% contamination would be acceptable.
For the unified-model anchor we also run UniAD under the same protocol. UniAD is a transformer feature reconstructor with neighbor masking and feature jittering, and it reports 96.5% detection AUROC in the unified MVTec AD setting.
The closest bridging method is the instance-weighted transfer of Fan et al., reimplemented on our backbone. It weights whole target images by reconstruction error and does no class pruning. On its own digit task it reports 82.0% AUC on MNIST→USPS at 0.45 contamination. We will rerun that digit task as a sanity check of our reimplementation.
Two ablations isolate the key ingredient. The first is oracle pruning, where the true target class set is given; it separates the value of pruning from the value of estimating which classes to prune. The second is a soft-weight variant that scales class tokens by $w_c$ rather than removing them. We also run an untrimmed-residual variant with $q = 0$ to show whether trimming is what protects the class estimate from defects.
Why not just…?
Why not just estimate which classes are present with a classifier, the usual partial-adaptation recipe? This option is a real threat for MVTec AD categories. They are visually very distinct, and nearest-prototype classification on pretrained features may identify a bottle line versus a screw line trivially, even under shift. We will therefore run this estimator as a drop-in replacement: averaged softmax over pretrained-feature prototypes, as in DRCN. If it matches the residual estimator, we will say so plainly and adopt it. The contribution then rests on pruning and defect-masked adaptation. We expect the residual estimator to matter mainly on fine-grained or heavily shifted categories, such as ADNet's 154 Industry categories, where prototype predictions become sparse and noisy at small overlap ratios.
Why not just train a fresh detector on the target images? The target pool is unlabeled and contaminated. Shallow detectors fit only on target features do poorly: an Isolation Forest reaches 57.7% AUROC on Office-Home Product→Clipart in Anomaly Detection with Domain Adaptation, and 73.0% on MNIST→USPS in Fan et al.. A deep one-for-one model trained on contaminated data risks learning the defects as normal. We will include a target-only reconstructor trained with the same patch masking. If it matches our method when the target pool is large, the honest conclusion is that transfer pays off only when target data is scarce. We will therefore report results as a function of pool size.
Why not just fine-tune the whole unified model on the target pool with all classes kept? This option is exactly the ROADS baseline, and the oracle-pruning ablation tests whether keeping absent classes hurts. If oracle pruning gives no gain over the all-class model at zero shift and zero contamination, the cross-class shortcut claim is false. The proposal would then reduce to defect-masked adaptation.
Proposed Experiments
Target lines. We sample target lines of 3, 6 and 9 categories from the 27 source categories, with five random subsets each. Unlabeled pools mix normal and defective test-style images at contamination rates of 0%, 10% and 30%. Shift comes from the corruptions used by ROADS (Gaussian noise and blur) plus color and illumination changes, and is evaluated on held-out target images. For natural shift, we use ADNet. There we train on Industry categories and deploy on subsets of its other domains where categories overlap, which tests a small overlap ratio at scale. On the ADNet unified setting, its context-guided mixture-of-experts reports 83.2% image AUROC and 93.1% pixel AUROC.
Metrics. We report image AUROC, pixel AUROC and PRO / AUPRO for detection and localization. For class-set estimation we report precision and recall of the recovered class set.
Decisive checks. The first decisive check is oracle pruning at zero shift: it must improve PRO on the target subset over the all-class model, or the central mechanism fails. The second is the class-set recall of the trimmed residual estimator at 30% contamination: it should stay high while the untrimmed estimator degrades. The third is end-to-end: the full method must beat ROADS under matched budgets at nonzero contamination.
References
- Partial Domain Adaptation Using Selective Representation Learning For Class-Weight Computation
- ROADS: Robust Prompt-Driven Multi-Class Anomaly Detection Under Domain Shift
- Toward Multi-class Anomaly Detection: Exploring Class-aware Unified Model against Inter-class Interference
- Importance Weighted Adversarial Discriminative Transfer for Anomaly Detection
- Deep Residual Correction Network for Partial Domain Adaptation
- ADNet: A Large-Scale and Extensible Multi-Domain Benchmark for Anomaly Detection Across 380 Real-World Categories
- A Unified Model for Multi-class Anomaly Detection
- Anomaly Detection with Domain Adaptation