Hierarchical Semi-supervised Contrastive Learning for Contamination-Resistant Anomaly Detection

Gaoang Wang, Yibing Zhan, Xinchao Wang, Mingli Song, Klara Nahrstedt

Abstract

Anomaly detection (AD) is critical for identifying deviations from normal patterns, yet real-world datasets are frequently "contaminated" with unlabeled anomalies. Traditional methods often struggle with such noise or require complex, multi-stage training pipelines. We introduce Hierarchical Semi-supervised Contrastive Learning (HSCL), an end-to-end framework that organizes contrastive learning into a three-level hierarchy: sample-to-sample, sample-to-prototype, and normal-to-abnormal relations. By utilizing differentiable prototypes and a soft-weighting strategy for unlabeled data, HSCL achieves state-of-the-art performance on benchmarks like CIFAR-10 and ImageNet, demonstrating significant robustness to contamination and label scarcity.

Introduction

The goal of Anomaly Detection (AD) is to identify samples that deviate significantly from a learned normal distribution. While many existing techniques assume a "clean" training set consisting solely of normal data, practical applications often involve contaminated datasets where a small percentage of anomalies are mixed in without labels.

Current contrastive learning approaches for AD face two primary limitations. First, they often focus exclusively on instance-level relations, neglecting the global structure of the normal data distribution. Second, they typically rely on multi-stage processes—pre-training followed by fine-tuning—which are computationally intensive and prone to suboptimal convergence when noise is present. HSCL addresses these issues by providing a unified, end-to-end learning objective.

The HSCL Framework

HSCL builds contamination-resistant representations by optimizing three distinct levels of contrastive relations simultaneously.

Conceptual overview of the three hierarchical contrastive modules: Sample-to-Sample, Sample-to-Prototype, and Normal-to-Abnormal.

Hierarchical Contrastive Modules

  1. Sample-to-Sample (S-S) Module: This module employs a standard InfoNCE loss to learn rich semantic features. By pushing different instances apart in the embedding space, the model develops a granular understanding of the data's feature manifold.
  2. Sample-to-Prototype (S-P) Module: A key innovation of HSCL is the introduction of differentiable "prototypes" that act as anchors for the normal data distribution. The loss function pulls labeled normal samples toward these prototypes while pushing known anomalies away, establishing a stable reference for "normalcy."
  3. Normal-to-Abnormal (N-A) Module: To handle unlabeled, potentially contaminated data, HSCL uses a soft-weighting strategy. It assigns weights to unlabeled samples based on their proximity to the learned prototypes. Samples that appear more "normal" are prioritized for contrast against known anomalies, effectively mining the contaminated set for useful training signals without being misled by hidden outliers.
The complete HSCL architecture, showing the end-to-end pipeline from contaminated input data to the final learned representation space.

Unlike previous methods that require offline clustering or sequential fine-tuning, HSCL is fully end-to-end. This joint optimization ensures that the encoder, prototypes, and decision boundaries evolve together, leading to more robust and discriminative features.

Experimental Evaluation

The researchers evaluated HSCL across several standard benchmarks, including CIFAR-10, CIFAR-100, LSUN, and ImageNet. The framework was tested under three challenging scenarios: semi-supervised AD with limited labels, contaminated AD (5-10% hidden anomalies), and cross-dataset generalization.

Key Results

  • State-of-the-Art Accuracy: In a CIFAR-10 scenario with 10% contamination, HSCL achieved an AUROC of 97.3%, a substantial improvement over the previous state-of-the-art method, Elsa+ (91.1%).
  • Label Efficiency: HSCL remains highly effective even with minimal supervision. With only 1% of the data labeled, it reached 96.4% AUROC on CIFAR-10, whereas competing semi-supervised methods like SSAD achieved only ~73%.
  • Robust Generalization: In cross-dataset tests (e.g., training on CIFAR-10 and testing against ImageNet anomalies), HSCL achieved near-perfect scores (99.8% AUROC), indicating that it learns a highly generalizable boundary of normalcy.

Conclusion

HSCL provides a powerful and efficient solution for anomaly detection in the presence of data contamination. By integrating sample-level and prototype-level relations into a single hierarchical objective, it creates a "north star" for normalcy that is resistant to noise. Its end-to-end nature and superior performance in low-label regimes make it a practical choice for real-world deployment where clean, fully labeled datasets are rare. Future work will explore extending this hierarchical approach to fully unsupervised settings.

Summary updated

BibTeX
@inproceedings{wang2022hierarchical,
  author = {Gaoang Wang and Yibing Zhan and Xinchao Wang and Mingli Song and Klara Nahrstedt},
  title = {{Hierarchical Semi-supervised Contrastive Learning for Contamination-Resistant Anomaly Detection}},
  booktitle = {European Conference on Computer Vision},
  year = {2022},
  doi = {10.1007/978-3-031-19806-9\_7},
}
Figure