Unilaterally Aggregated Contrastive Learning with Hierarchical Augmentation for Anomaly Detection

Guodong Wang, Yunhong Wang, Jie Qin, Dongming Zhang, Xiuguo Bao, Di Huang

TL;DR

UniCon-HA is a novel contrastive learning framework for anomaly detection that achieves state-of-the-art results by simultaneously pulling all "normal" data points into a single compact cluster while pushing "virtual outliers" apart. By combining a soft-weighting mechanism to filter out noisy augmentations and a hierarchical training strategy that matches augmentation strength to network depth, the authors create a more robust and precise boundary for identifying anomalies.

What Problem Does This Paper Address?

Anomaly Detection (AD) is the task of identifying "weird" samples that don't belong to the training distribution—critical for everything from medical diagnosis to industrial quality control. Since we rarely have examples of every possible "bad" thing during training, most models learn only from "normal" data (inliers).

Recent methods use self-supervised contrastive learning, where the model learns by comparing different versions of the same image. To simulate anomalies, they often create "virtual outliers" by rotating images (e.g., a 90-degree cat). However, standard contrastive learning has a fundamental mismatch with AD: it tries to push every instance away from every other instance. In AD, we actually want all normal samples to stick together in a tight group, while only pushing the outliers away. As shown in Figure 1, existing methods like DROC or CSI often result in decision regions that are either too loose or push inliers too far apart.

Figure 1: The decision regions (light yellow) of RotNet [26], DROC [49], CSI [51] and our UniCon-HA with ro- tation used to create virtual outliers. (a) RotNet models the inlier distribution by predicting rotation angles through a 4- way classifier; (b) DROC performs instance discrimination within the union of inliers and their rotations, resulting in a uniform distribution of data points; (c) CSI combines con- trastive learning with a rotation classifier, enclosing a sub- region for inliers; (d) Our UniCon-HA explicitly promotes the concentration of inliers and the dispersion of rotated vir- tual outliers, yielding the most compact decision region.

Methods

The authors introduce Unilaterally Aggregated Contrastive Learning with Hierarchical Augmentation (UniCon-HA). The core components are:

  1. UniCLR Loss: Unlike standard contrastive learning, this "unilateral" approach treats all inliers as a single class, pulling them together (supervised contrastive). Conversely, it treats each virtual outlier (created via rotation) as its own distinct class, pushing them apart to fill the remaining latent space.
  2. Soft Aggregation (SA): Strong data augmentations (like extreme cropping) can sometimes make a normal image look like an outlier—a problem called "semantic drift." UniCon-HA calculates an affinity matrix to see how much an augmented view deviates from the general inlier distribution. It then down-weights these "noisy" views so they don't ruin the compact inlier cluster.
  3. Hierarchical Augmentation (HA): Inspired by curriculum learning, the model applies weak augmentations at shallow layers of the neural network and progressively stronger augmentations at deeper layers. This helps the model learn both low-level features and high-level semantics for better concentration.
Figure 2: Overview of the proposed UniCon-HA for anomaly detection: (a) we explicitly encourage concentration of inliers and dispersion of virtual outliers generated by distributionally-shifted transformations with rotation being an example. To ensure a purified inlier concentration, we propose soft aggregation to re-weight each view of inliers generated by standard data augmentation e.g. random crop, based on its average similarities with all other inliers; (b) to prompt a higher concentration, we employ an easy-to-hard hierarchical augmentation strategy and distribute contrastive aggregation at different stages of the network based on the strengths of data augmentations.

Datasets

The model was evaluated across several standard benchmarks and settings:

  • CIFAR-10 & CIFAR-100: Used for one-class and multi-class AD settings.
  • ImageNet-30: A subset of ImageNet used to test scalability to higher-resolution images.
  • MVTec-AD: A realistic industrial dataset for defect detection.
  • Outlier Exposure (OE): The authors also tested the model using the "80 Million Tiny Images" dataset as an auxiliary source of real-world outliers to further boost performance.

Key Insights and Ideas

  • The Power of Unilateralism: The biggest "aha" moment is realizing that for AD, instance discrimination is actually counter-productive for inliers. By treating all inliers as one group, the model creates a much more meaningful "normality" center.
  • Filtering the Noise: The "Soft Aggregation" mechanism acknowledges that not all data augmentations are helpful. By re-weighting views based on their similarity to the group, the model becomes much more robust to the "semantic drift" that plagues other contrastive methods.
  • Depth Matters: Matching augmentation strength to network depth (Hierarchical Augmentation) allows the model to capture a multi-scale representation of what makes an image "normal," leading to a tighter decision boundary.

Key Results

UniCon-HA consistently outperformed state-of-the-art competitors like CSI and DROC across various settings.

  • One-class CIFAR-10: Achieved a mean AUROC of 95.4%, which improved to 96.9% with Outlier Exposure.
  • ImageNet-30: Reached an AUROC of 93.2%, significantly higher than CSI's 91.6%.
  • Labeled Multi-class: The method generalizes well; when class labels are available for inliers, UniCon-HA reaches near-perfect scores (e.g., 99.8% AUROC on SVHN).
Table showing AUROC scores on one-class benchmarks. UniCon-HA shows consistent superiority.

Limitations and Future Work

While highly effective, the paper notes that the choice of "shifting transformations" (like rotation) is crucial. While rotation works exceptionally well for general objects, it might be less effective for datasets where orientation isn't a defining feature of an anomaly.

Future work could explore more diverse or learned transformations to create virtual outliers, potentially making the system even more robust to different types of real-world anomalies. Additionally, while the soft aggregation helps, the model still relies on a large number of training epochs (2,048) to reach peak performance, suggesting room for optimization in training efficiency.

Summary updated

BibTeX
@inproceedings{wang2023unilaterally,
  author = {Guodong Wang and Yunhong Wang and Jie Qin and Dongming Zhang and Xiuguo Bao and Di Huang},
  title = {{Unilaterally Aggregated Contrastive Learning with Hierarchical Augmentation for Anomaly Detection}},
  booktitle = {IEEE/CVF International Conference on Computer Vision},
  year = {2023},
}

Loading related content...

Figure