[Paper Review] Mean-Shifted Contrastive Loss for Anomaly Detection
This paper proposes the Mean-Shifted Contrastive (MSC) loss to improve anomaly detection by fine-tuning ImageNet-pretrained features for one-class classification. Unlike standard contrastive learning, which fails due to poor optimization dynamics on compact, pre-trained features, MSC reweights the contrastive objective using feature mean shifts, achieving a new state-of-the-art 98.6% ROC-AUC on CIFAR-10.
Deep anomaly detection methods learn representations that separate between normal and anomalous images. Although self-supervised representation learning is commonly used, small dataset sizes limit its effectiveness. It was previously shown that utilizing external, generic datasets (e.g. ImageNet classification) can significantly improve anomaly detection performance. One approach is outlier exposure, which fails when the external datasets do not resemble the anomalies. We take the approach of transferring representations pre-trained on external datasets for anomaly detection. Anomaly detection performance can be significantly improved by fine-tuning the pre-trained representations on the normal training images. In this paper, we first demonstrate and analyze that contrastive learning, the most popular self-supervised learning paradigm cannot be naively applied to pre-trained features. The reason is that pre-trained feature initialization causes poor conditioning for standard contrastive objectives, resulting in bad optimization dynamics. Based on our analysis, we provide a modified contrastive objective, the Mean-Shifted Contrastive Loss. Our method is highly effective and achieves a new state-of-the-art anomaly detection performance including $98.6\%$ ROC-AUC on the CIFAR-10 dataset.
Motivation & Objective
- To address the poor performance of standard contrastive learning when fine-tuning ImageNet-pretrained features for anomaly detection.
- To analyze why standard contrastive objectives fail on pre-trained features due to poor initialization and optimization dynamics.
- To develop a new contrastive loss that adapts pre-trained features effectively for one-class anomaly detection.
- To demonstrate that pre-trained features, when fine-tuned with the proposed loss, surpass self-supervised and prior transfer methods.
- To validate the method across diverse architectures and anomaly detection settings, including multi-class and k-NN-based scoring.
Proposed method
- Propose a modified contrastive loss, the Mean-Shifted Contrastive (MSC) loss, which reweights positive and negative pairs based on the mean shift of features.
- Use the mean of the feature embeddings as a learnable center, adjusting the contrastive objective to account for the compactness of pre-trained features.
- Apply the MSC loss during fine-tuning of pre-trained ImageNet features on normal training data only, without any anomalous labels.
- Integrate the MSC loss with standard one-class classification frameworks, such as k-NN or center-based scoring, for inference.
- Enable efficient inference by combining MSC features with k-means compression of the normal training set to reduce gallery size.
- Train and evaluate on standard benchmarks like CIFAR-10, using both single-class and multi-class anomaly detection settings.
Experimental results
Research questions
- RQ1Why does standard contrastive learning fail when fine-tuning ImageNet-pretrained features for anomaly detection?
- RQ2How can the optimization dynamics of contrastive learning be improved when initialized with pre-trained features that concentrate in a compact subspace?
- RQ3Can a modified contrastive objective outperform both standard contrastive learning and center-based objectives like DeepSVDD or PANDA in one-class anomaly detection?
- RQ4Does the proposed MSC loss generalize across different backbone architectures, including ViT and DenseNet?
- RQ5To what extent can pre-trained features, when fine-tuned with MSC, improve anomaly detection performance compared to self-supervised or outlier exposure methods?
Key findings
- Standard contrastive learning fails to improve anomaly detection when initialized with ImageNet-pretrained features due to poor optimization dynamics on compact feature manifolds.
- The proposed Mean-Shifted Contrastive (MSC) loss achieves 98.6% ROC-AUC on CIFAR-10, setting a new state-of-the-art for anomaly detection.
- MSC outperforms PANDA and DN2 across multiple architectures, including ViT and DenseNet, where PANDA fails or underperforms.
- MSC generalizes well to multi-class anomaly detection settings, where normal data has a multi-modal distribution, outperforming methods that assume uni-modality.
- k-NN anomaly detection with MSC features and k-means compressed galleries achieves 97.2% ROC-AUC with full training set, and 97.0% with only 100 means, showing strong efficiency-accuracy trade-offs.
- The MSC loss is robust to backbone size, with performance improving on larger networks, unlike self-supervised methods like CSI, which show no improvement with deeper architectures.
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.