[Paper Review] Contrastive Predictive Coding for Anomaly Detection
This paper proposes CPC-AD, a contrastive learning-based method that directly uses the InfoNCE loss from Contrastive Predictive Coding (CPC) as an anomaly score for both anomaly detection and segmentation in images. By modifying negative sampling during inference and removing the autoregressive component, the method achieves state-of-the-art detection performance on MVTec-AD and generates interpretable segmentation masks without requiring pre-trained models or artificial augmentations.
Reliable detection of anomalies is crucial when deploying machine learning models in practice, but remains challenging due to the lack of labeled data. To tackle this challenge, contrastive learning approaches are becoming increasingly popular, given the impressive results they have achieved in self-supervised representation learning settings. However, while most existing contrastive anomaly detection and segmentation approaches have been applied to images, none of them can use the contrastive losses directly for both anomaly detection and segmentation. In this paper, we close this gap by making use of the Contrastive Predictive Coding model (arXiv:1807.03748). We show that its patch-wise contrastive loss can directly be interpreted as an anomaly score, and how this allows for the creation of anomaly segmentation masks. The resulting model achieves promising results for both anomaly detection and segmentation on the challenging MVTec-AD dataset.
Motivation & Objective
- To address the challenge of unsupervised anomaly detection in real-world applications where labeled anomalous data is scarce.
- To bridge the gap between contrastive learning and end-to-end anomaly detection and segmentation in images.
- To enable direct use of the contrastive loss as both an anomaly score and a basis for segmentation masks.
- To develop a method that is generalizable across classes and does not rely on dataset-specific data augmentations or pre-trained models.
- To demonstrate that CPC's patch-wise contrastive loss can be repurposed for both detection and localization of anomalies.
Proposed method
- The method employs the Contrastive Predictive Coding (CPC) framework, using patch-wise representations from a single image for contrastive learning.
- The InfoNCE loss between positive and negative patch pairs is directly interpreted as an anomaly score for each patch.
- During inference, negative samples are reconfigured so that anomalous patches can only appear in the positive set, improving detection sensitivity.
- The autoregressive component of CPC is removed to simplify the model and focus on representation learning for anomaly detection.
- Anomaly segmentation masks are generated by up-sampling the patch-wise InfoNCE scores to pixel-level resolution using averaging over overlapping patches.
- The model is trained from scratch using only normal training data, without any artificial anomalies or pre-training.
Experimental results
Research questions
- RQ1Can the contrastive loss from CPC be directly used as an anomaly score for image-level anomaly detection?
- RQ2Can the same contrastive loss be leveraged to generate accurate pixel-level anomaly segmentation masks?
- RQ3How does the performance of CPC-AD compare to state-of-the-art methods on the MVTec-AD benchmark for both detection and segmentation?
- RQ4Does removing the autoregressive component and adjusting negative sampling improve anomaly detection performance?
- RQ5Can a self-supervised contrastive model trained from scratch achieve competitive results without pre-training or data augmentation?
Key findings
- CPC-AD achieves a mean AUROC of 0.901 on the MVTec-AD test set, outperforming kernel density estimation and autoencoding baselines.
- The method achieves a 0.998 AUROC on the bottle class, surpassing the CutPaste model on this class.
- For anomaly segmentation, CPC-AD outperforms GAN-based methods like AnoGAN and matches or exceeds other autoencoding and contrastive baselines on most classes.
- Despite lower segmentation scores on some classes (e.g., 0.809 AUROC on carpet), the method produces visually accurate masks with minimal background noise.
- The model performs particularly well on texture-rich classes, suggesting robustness to structural variations.
- The approach is generalizable and does not require dataset-specific data augmentations or pre-trained models, making it more broadly applicable than methods like CutPaste.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.