Source-linked AI summary
ReContrast: Domain-Specific Anomaly Detection via Contrastive Reconstruction
Jia Guo, Shuai Lu, Lize Jia, Weihang Zhang, Huiqi Li
TL;DR
Frozen encoders pretrained on natural images transfer poorly to industrial and medical UAD domains, while adapting only a layer after the encoder may not recover lost domain information. ReContrast jointly optimizes the feature-reconstruction network with embedded contrastive-learning elements, and the authors report superior performance across two industrial and three medical benchmarks.
Problem
Frozen natural-image encoder features transfer poorly to target UAD domains, and a layer after a frozen encoder may not recover domain-specific information already lost during extraction.
Source: §1 · p. 2Method
ReContrast jointly optimizes the encoder and decoder end-to-end, embedding contrastive-learning elements into feature-reconstruction UAD.
Source: §1 · p. 2Results
ReContrast reports superior performance across two industrial and three medical benchmarks, including 99.5% image-level AUROC on MVTec AD and nearly half the previous best error.
Source: §1 · p. 2Takeaways & Limitations
The authors conclude that optimizing encoders may further boost UAD on image modalities far from the natural-image domain.
Source: §4 · p. 10Reported performance can depend on random seeds because UAD settings lack validation sets, leaving the last-epoch result vulnerable to a loss spike and performance dip.
Source: §5 · p. 10
Abstract
from arXiv · showhide
Most advanced unsupervised anomaly detection (UAD) methods rely on modeling feature representations of frozen encoder networks pre-trained on large-scale datasets, e.g. ImageNet. However, the features extracted from the encoders that are borrowed from natural image domains coincide little with the features required in the target UAD domain, such as industrial inspection and medical imaging. In this paper, we propose a novel epistemic UAD method, namely ReContrast, which optimizes the entire network to reduce biases towards the pre-trained image domain and orients the network in the target domain. We start with a feature reconstruction approach that detects anomalies from errors. Essentially, the elements of contrastive learning are elegantly embedded in feature reconstruction to prevent the network from training instability, pattern collapse, and identical shortcut, while simultaneously optimizing both the encoder and decoder on the target domain. To demonstrate our transfer ability on various image domains, we conduct extensive experiments across two popular industrial defect detection benchmarks and three medical image UAD tasks, which shows our superiority over current state-of-the-art methods.
1 Introduction
UAD learns to detect and localize anomalies from normal-only images, but frozen features pretrained on natural images transfer poorly to industrial and medical domains. ReContrast jointly optimizes the UAD network and reports superior performance across industrial and medical benchmarks.
1 Introduction
- Frozen natural-image encoder features transfer poorly to varied UAD modalities, and a learnable layer after a frozen encoder may not recover domain-specific information already lost.This limitation is especially relevant when the target domain is far from natural images, such as medical imaging.Source: §1 · pp. 1–2
- ReContrast applies feature-reconstruction UAD end-to-end, jointly optimizing the encoder and decoder while incorporating contrastive-learning elements to address feature degradation and shortcut behavior.It also uses two encoders in different domains to generate views and hard-mines normal regions that are difficult to reconstruct.Source: §1 · p. 2
- ReContrast reports superior performance across MVTec AD, VisA, and three medical benchmarks, reaching 99.5% image-level AUROC on MVTec AD and nearly halving the previous best error.The method is evaluated without elaborately designed memory banks or handcrafted pseudo anomalies.Source: §1 · p. 2
- Global cosine distance introduces globality into point-by-point cosine distance to improve training stability without pooling away regional distinctions.The objective is inspired by global average pooling in contrastive learning.Source: §1 · p. 3
- ReContrast uses stop-gradient to prevent encoder pattern collapse and generates contrastive pairs without image augmentation to avoid introducing potential anomalies.These choices are part of its contrastive feature-reconstruction design.Source: §1 · pp. 2–3
2 Method: From Reconstruction to ReContrast
ReContrast builds on feature-reconstruction UAD and progressively addresses instability, encoder-feature degradation, and identical shortcuts with contrastive-learning-inspired components. Its design combines global cosine optimization, stop-gradient, augmentation-free cross-reconstruction, and hard-normal mining.
2 Method: From Reconstruction to ReContrast
- The method section develops three cohesive contrastive-learning-inspired components through a progressive exploration from feature reconstruction to ReContrast.The progression is presented as a way to explain the method’s motivation.Source: §2 · p. 3
2.1 Preliminary: Reverse Distillation
- RD4AD trains a decoder to reconstruct encoder feature maps, expecting reconstruction to fail on anomalous regions at inference.The stated Lregion training loss produced 95.3% I-AUROC on MVTec AD, versus 98.5% reported in the RD4AD paper.Source: §2.1 · pp. 3–4
2.2 Global Cosine Similarity
- Global cosine distance makes Config.B’s training more favorable and stable than Config.A’s, while measuring consistency across feature points rather than focusing on individual regions.The authors observe a flatter overall Smap landscape for Lglobal but a sharper landscape near its final minimum, and note that the mechanism remains under investigation.Source: §2.2 · pp. 4–5
2.3 Feature Degradation of Optimized Encoder
- Jointly optimizing encoder and decoder can drive encoder features toward easy-to-reconstruct, indiscriminative representations, with Config.C’s feature diversity dropping during training.Config.B’s feature diversity stays constant; the authors attribute the performance degeneration to encoder-feature degradation.Source: §2.3 · p. 5
2.4 Stop Gradient
- Stop-gradient blocks direct encoder gradients while retaining a decoder-mediated path, and Config.D extracts more discriminative features without degeneration.Config.D performs better than Config.C early in training, but may later drop as the decoder learns an identical shortcut.Source: §2.4 · p. 6
2.5 Contrastive Pairs
- Because image augmentation can introduce potential anomalies and spatial transforms disrupt regional correspondence, ReContrast constructs two views without augmentation.The adapted and frozen encoders provide the two views for cross-reconstruction.Source: §2.5 · pp. 6–7
- Cross-reconstruction pairs an adapted encoder’s domain-specific view with a frozen encoder’s pre-trained-domain view, while each reconstructs the other’s features.The two-view configuration sums six upsampled cosine-distance maps; feature diversity holds and slightly increases during training.Source: §2.5 · p. 7
2.6 Magnify Epistemic Error by Hard-Normal Mining
- Hard-normal mining discards gradients for easy regions rather than removing their feature points, focusing optimization on hard-normal regions.It activates fewer normal regions than Lglobal and can mitigate overfitting to easy training samples.Source: §2.6 · p. 7
3 Experiments
The experiments evaluate ReContrast on industrial defect detection and medical disease screening, across per-category and unified multi-class settings. Results cover detection, segmentation, and ablations of the proposed components.
3 Experiments
- The experiments assess ReContrast on industrial inspection and medical screening, including both per-category and unified multi-class evaluation.Source: §3 · p. 7
3.1 Experimental Settings
- Experiments span MVTec AD, VisA, OCT2017, APTOS, and ISIC2018, using I-AUROC, medical F1 and accuracy, and segmentation P-AUROC and AUPRO.The default encoder is ImageNet-pretrained WideResNet50; encoder parameters use a lower learning rate than the decoder and bottleneck.Source: §3.1 · pp. 7–8
3.2 Anomaly Detection and Segmentation on Industrial Images
- 99.5% average I-AUROC on MVTec AD; ReContrast also achieves 95.2% AUPRO, 1.3% above RD4AD.It is also reported as state of the art on P-AUROC and on texture and object category averages.Source: Table 1 · p. 8, Table 2 · p. 8, §3.2 · p. 8
- 97.5% average I-AUROC on VisA, 1.5% above RD4AD; its 92.6% AUPRO is 1.4% above PatchCore.Source: Table 3 · p. 8, §3.2 · p. 9
3.3 Multi-Class Anomaly Detection with A Unified Model
- 98.2% I-AUROC on unified MVTec AD and 95.1% on unified VisA exceed prior multi-class results.On MVTec AD, ReContrast exceeds UniAD’s 96.5% by 1.7%; on VisA, it exceeds RD4AD’s 92.7% by 2.4%.Source: Table 4 · p. 9, §3.3 · p. 9
3.4 Anomaly Detection on Medical Images
- ReContrast achieves the best results across all metrics on APTOS and ISIC2018, and comparable best results on OCT2017.The reported comparison includes methods designed for medical images and methods proposed for domain adaptation.Source: §3.4 · p. 9, Table 5 · p. 10
3.5 Ablation Study
- Adding global loss, stop-gradient, contrastive pairs, and the heatmap-based variant progressively addresses collapse and improves the feature-reconstruction baseline.The complete method, using Lglobal−hm, achieves state-of-the-art performance; Lglobal−hm also improves the baseline reconstruction method alone.Source: §3.5 · p. 9, Table 6 · p. 10
4 Conclusion
ReContrast jointly optimizes the UAD network end-to-end, embedding contrastive-learning elements in feature reconstruction. Experiments across industrial and medical datasets demonstrate superiority, while the authors point to broader image modalities as a potential application.
- ReContrast jointly optimizes all parameters end-to-end to address transfer from pre-trained encoders.Source: §4 · p. 10
- Its contrastive-learning elements are embedded in epistemic UAD to avoid pattern collapse, training instability, and identical shortcut.Source: §4 · p. 10
- Experiments on MVTec AD, VisA, and three medical datasets demonstrate superiority over prior methods.Source: §4 · p. 10
- The authors suggest encoder optimization may further extend UAD to image modalities far from the natural-image domain.Source: §4 · p. 10
5 Limitations
The paper focuses on regional-defect UAD rather than semantic one-class classification, and reports that ReContrast still has some training instability.
- The application scope is regional defects in semantically similar objects, not semantic one-class classification of different object classes.Examples contrast a good cable with a spoiled cable versus a cat with other animals.Source: §5 · p. 10
- Training instability remains: without validation sets, whether the reported last epoch falls in a loss spike or performance dip depends on random seeds.The authors also observed instability when running RD4AD, CFA, and SimpleNet code.Source: §5 · p. 10
Appendices
The appendices formulate UAD as training on normal samples and testing on normal and anomalous images, with anomaly identification and localization as goals. Related work covers reconstruction, pseudo-anomaly, feature-memory, and adaptation approaches.
Appendices
- UAD trains on normal samples, then identifies anomalous test images while localizing anomalous regions.Source: Appendices · p. 14
A Related Work
- Epistemic methods rely on different inference responses to seen and unseen inputs; feature reconstruction targets pre-trained encoder features, while distillation trains a student to mimic a teacher.Pixel reconstruction may restore subtle or pixel-similar anomalies, and feature-reconstruction encoders are frozen to avoid trivial solutions.Source: A Related Work · p. 14
- Pseudo-anomaly methods synthesize defects, while feature-memory methods store or model normal features; both have stated generalization or computational constraints.Pseudo-anomaly methods depend on matching synthetic to real defects; memory methods require costly feature storage, processing, and matching.Source: A Related Work · p. 14
- CFA and SimpleNet adapt frozen encoder outputs with a linear layer, which may not recover lost domain-specific information; OCC-focused pre-training has also underperformed in UAD.The cited OCC approaches report I-AUROC below 90% on MVTec AD.Source: A Related Work · p. 14
B Datasets
The experiments use two industrial defect benchmarks and three medical-image anomaly-detection datasets, with dataset-specific training and test splits and image preprocessing.
B Datasets
- MVTec AD comprises 15 categories, with 3,629 normal training images and 1,725 normal and anomalous test images; anomalous images have pixel-level annotations.Images are resized to 256×256.Source: B Datasets · p. 14
- VisA contains 12 sub-datasets and 9,621 normal plus 1,200 anomalous images, split into training and test sets following its benchmark setting.Pixel-level annotations are available for anomalous images, and images are resized to 256×256.Source: B Datasets · p. 15
- OCT2017 treats drusen, DME, and CNV as anomalies against normal images, using 26,315 normal training images and 1,000 test images.All images are resized to 256×256.Source: B Datasets · p. 15
- APTOS uses grade 0 as normal and grades 1–4 as anomalous; 1,000 normal images train the model, while the remaining 2,662 images form the test set.Fundus regions are cropped and resized to 256×256.Source: B Datasets · p. 15
- ISIC2018 treats nevus as normal and other classes as anomalous, training on 6,705 normal images and testing on the 193-image official validation set.Images are center-cropped to 224×224 after resizing; because normal and anomalous images are different lesions, the study uses mean rather than maximum Smap as Simg.Source: B Datasets · p. 15
C Complete Implementation Details
Implementation uses an ImageNet-pretrained WideResNet50 encoder and an RD4AD-style decoder, with dataset-specific training schedules and evaluation settings.
C Complete Implementation Details
- The default encoder is ImageNet-pretrained WideResNet50, paired with an upside-down RD4AD decoder and the same bottleneck.Decoder layers use separate 1×1 convolutions to reconstruct frozen-encoder and trained-encoder features.Source: C Complete Implementation Details · p. 15
- AdamW uses β=(0.9,0.999), weight decay 1e-5, and learning rates 2e-3 for new parameters and 1e-5 for pretrained encoder parameters.Training runs 3,000 iterations per VisA sub-dataset, 2,000 for MVTec AD and ISIC2018, and 1,000 for APTOS and OCT2017.Source: C Complete Implementation Details · p. 15
- Batch size is 16 for industrial datasets and 32 for medical datasets; α rises linearly from -3 to 1 during the first tenth of training, then remains 1.Encoder batch-normalization layers are normally in train mode, but use pretrained statistics for listed categories with observed instability and performance drops.Source: C Complete Implementation Details · p. 15
- Industrial comparison results come from original papers or the benchmark paper, while medical results use prior reported values when available and otherwise official-code reproductions.Experiments use Python 3.8, PyTorch 1.12.0 with CUDA 11.3, and NVIDIA GeForce RTX3090 GPUs with 24GB memory.Source: C Complete Implementation Details · p. 15
D.1 Additional Experimental Results
The appendix adds category-level and repeated-run reporting, then presents qualitative anomaly maps, including a comparison of two loss variants.
D.1 Additional Experimental Results
- Category-level MVTec AD segmentation results are reported in Table A1, complementing the averaged results in Table 2.The main-paper results use a single random seed; Table A2 reports mean and standard deviation over three seeds (1, 11, and 111).Source: §D.1 · pp. 15–16, Table A1 · p. 16, Table A2 · p. 16
- Table A3 gives category-level VisA I-AUROC, P-AUROC, and AUPRO, alongside averaged results reported in Table 3.The appendix also points to per-category MVTec AD P-AUROC and AUPRO results in Table A1.Source: §D.1 · p. 16, Table A3 · p. 16, Table A1 · p. 16
D.2 Qualitative Visualization
- In qualitative segmentation visualizations, hard-normal regions are less activated with Lglobal−hm than with Lglobal.Additional figures show VisA and medical-image maps; Smap values are min-max normalized to 0–1 for visualization.Source: §D.2 · p. 16
D.3 Additional Ablation Study
Additional ablations examine the α setting, encoder backbone, and inference feature-map choices, including comparisons with RD4AD and a two-encoder baseline.
D.3 Additional Ablation Study
- Lglobal−hm is insensitive to discarding rates from 50% to 93%, and α=1 works well in most circumstances under the assumed Gaussian regional-distance distribution.The reported rates are 2.3%, 15.9%, 50%, 69.1%, 84.1%, 93.3%, and 97.7% for α values -2, -1, 0, 0.5, 1, 1.5, and 2, respectively.Source: §D.3 · pp. 16–17, Table A4 · p. 17
- ResNet18, ResNet50, and WideResNet50 all yield excellent results with default hyperparameters, and each outperforms its corresponding RD4AD feature-reconstruction counterpart.ReContrast with ResNet18 is comparable to RD4AD with WideResNet50; Table A5 also reports parameters and MACs.Source: §D.3 · p. 17, Table A5 · p. 17
- On MVTec, the domain-specific encoder alone reaches 99.38% I-AUROC versus 99.45% for default ReContrast and 98.86% for Config. B; on APTOS it reaches 97.73% versus 97.51% and 92.49%.The two-encoder Config. B ensemble reaches 98.94% on MVTec, nearly identical to baseline Config. B; the authors conclude ensembling contributes little and the domain-specific encoder is vital.Source: §D.3 · p. 17, Table A6 · p. 17
E Limitations
ReContrast is scoped to regional-defect UAD, where normal and anomalous images depict semantically similar objects. Its limitations include weaker performance on logical anomalies than a specialized method and training instability that can complicate batch-normalization choices.
E Limitations
- The method focuses on regional-defect UAD, where normal and anomalous samples are semantically similar, rather than one-class classification of semantically different objects.The paper notes that UAD methods generally target anomalous local regions, while OCC methods focus on whole-image representation deviation.Source: E Limitations · pp. 17–18
- ReContrast performs less favorably than GCAD on logical anomalies, though it still outperforms vanilla UAD methods not designed for them.The comparison is reported on MVTec LOCO.Source: E Limitations · p. 18
- Training remains unstable when encoder batch normalization is trained; without validation sets, such instability can complicate selecting the BN mode.UAD results reported at the last epoch can also depend on whether that epoch coincides with a loss spike and performance dip, which is related to random seeds.Source: E Limitations · p. 18
- One-class data can leave a pretrained feature channel barely or equally activated, making batch-normalization variance plus epsilon nearly zero and causing malfunction.Using pretrained running statistics in eval mode fixes the problem but loses the effect of batch normalization; variance and Adam-state adjustments yielded more stable training with comparable reported results.Source: E Limitations · p. 18
Related papers
This paper cites
- Auto-Encoding Variational Bayes2013
- Batch Normalization: Accelerating Deep Network Training by Reducing Internal Covariate Shift2015
- A Simple Framework for Contrastive Learning of Visual Representations2020
- Bootstrap your own latent: A new approach to self-supervised Learning2020
- Sharpness-Aware Minimization for Efficiently Improving Generalization2020
- Skin Lesion Analysis Toward Melanoma Detection 2018: A Challenge Hosted by the International Skin Imaging Collaboration (ISIC)2019