Abstract
Anomaly Detection focuses on identifying samples that deviate from the norm. When working with high-dimensional data such as images, a crucial requirement for detecting anomalous patterns is learning lower-dimensional representations that capture normal concepts seen during training. Recent advances in self-supervised learning have shown great promise in this regard. However, many of the most successful self-supervised anomaly detection methods assume prior knowledge about the structure of anomalies and leverage synthetic anomalies during training. Yet, in many real-world applications, we do not know what to expect from unseen data, and we can solely leverage knowledge about normal data. In this work, we propose Con2, which addresses this problem by setting normal training data into distinct contexts while preserving its normal properties, letting us observe the data from different perspectives. Unseen normal data consequently adheres to learned context representations while anomalies fail to do so, letting us detect them without any knowledge about anomalies during training. Our experiments demonstrate that our approach achieves state-of-the-art performance on various benchmarks while exhibiting superior performance in a more realistic healthcare setting, where knowledge about potential anomalies is often scarce.
TL;DR
Instead of trying to guess what an anomaly looks like, the $\text{CON}_2$ framework learns the "shape of normality" by leveraging natural symmetries in data. By creating two distinct but aligned representation spaces for normal samples, the model makes anomalies stand out as structural outliers that fail to fit into this dual-context geometry.
The Challenge of Anomaly Detection
Anomaly detection (AD) is the "needle in a haystack" problem of machine learning. In safety-critical fields like medicine, we have plenty of "normal" data (healthy scans) but very few examples of "anomalies" (rare diseases).
Current state-of-the-art methods usually take one of two paths:
- Synthetic Outliers: They create "fake" anomalies during training to teach the model what to avoid. However, in specialized fields, it is nearly impossible to simulate every possible way a lung X-ray or brain MRI could look "wrong."
- Pre-trained Models: They use models trained on massive datasets like ImageNet. The problem? A model that knows how to distinguish a cat from a dog isn't necessarily good at spotting a subtle tumor in a grayscale medical image.
The authors aim to learn informative, concentrated representations of normal data without ever needing to see—or simulate—an anomaly.
The CON2 Framework
The core of the paper is $\text{CON}_2$ (Context Contrasting with Content Alignment). The approach relies on a clever two-step training process using "context augmentations."
- Context Augmentations: The researchers identify transformations that change the look of an image but keep its meaning (e.g., inverting the colors of an X-ray or flipping an MRI vertically). A valid augmentation must be distinctive (the model can tell the original from the transformed) and aligned (the underlying structure remains the same).
- Context Contrasting: The model learns to push representations into two separate clusters based on their context (e.g., one cluster for "original" and one for "inverted").
- Content Alignment: Simultaneously, the model is forced to align these clusters. If Sample A is in the top-left of the "original" cluster, its inverted counterpart must also appear in the top-left of the "inverted" cluster.
At test time, normal samples fit perfectly into this aligned structure. Anomalies, however, lack the expected symmetries and fail to align across these two spaces, making them easy to flag. The authors propose two scoring methods: a high-accuracy Nearest Neighbor approach ($\mathcal{S}_{\text{NND}}$) and a more memory-efficient Gaussian Likelihood approach ($\mathcal{S}_{\text{LH}}$).
Geometric Alignment as a Signal
A key insight of $\text{CON}_2$ is that symmetry is a stronger signal than noise. Traditional self-supervised learning often uses random cropping or noise. $\text{CON}_2$ argues that using domain-specific symmetries (like the fact that an inverted X-ray is still a valid, albeit different-looking, X-ray) provides a much stronger "anchor" for defining normality.
By forcing the model to maintain two parallel versions of the world, the researchers create a "geometric constraint." An anomaly isn't just a point that is "far away"; it's a point that breaks the mathematical relationship between the two contexts. Furthermore, the authors found that $\text{CON}_2$ tends to learn elliptical clusters, allowing for efficient scoring using Gaussian likelihood.
Results and Benchmarks
The paper focuses heavily on specialized medical benchmarks where standard methods often struggle, including BreastMNIST, OctMNIST, Kvasir, and BR35H.
- Medical Dominance: $\text{CON}_2$ consistently outperformed popular baselines like SimCLR, CSI, and even specialized medical AD models. On the BR35H (Brain MRI) dataset, $\text{CON}_2$ achieved a perfect 100% AUROC.
- Zero-Shot Superiority: It outperformed "foundation" models like CLIP-AD. This suggests that for specialized domains, training a smaller model on the specific "normal" data is better than using a giant model trained on general internet images.
- Robustness: The method proved robust across different types of augmentations (Invert, Flip, Equalize), provided the augmentation satisfied the "distinctiveness" and "alignment" assumptions.
Limitations and Future Work
While the empirical results are strong, the current work is strictly image-based. Finding appropriate "context augmentations" for other data types, like time-series or graphs, remains an open challenge. Additionally, the success of the model depends on the human researcher choosing a good context augmentation. Future work could involve automatically learning which symmetries define a specific dataset to remove this heuristic dependency.
Summary updated