Anomaly Detection via Multi-Scale Contrasted Memory

Loïc Jezequel, Ngoc-Son Vu, Jean Beaudet, Aymeric HistacearXiv 2022 · DOI

Introduction

Deep Anomaly Detection (AD) aims to identify "out-of-distribution" samples within complex datasets. Despite significant progress, current state-of-the-art models often struggle with three primary challenges: the generalization paradox (balancing memory of edge-case normal samples with the ability to spot novel anomalies), the scale gap (detecting both local textural defects and global structural anomalies), and fragmented frameworks (the architectural divide between one-class and semi-supervised AD).

To address these issues, we present AnoMem, a novel two-stage framework that integrates multi-scale Modern Hopfield memory modules directly into a contrastive learning objective. By memorizing "normal" prototypes across multiple spatial resolutions, AnoMem provides a unified solution that excels in both one-class and semi-supervised settings.

The AnoMem Framework

AnoMem operates through a two-stage process designed to learn robust representations of normality and subsequently detect deviations from those learned patterns.

The AnoMem architecture: (a) Stage 1 involves memory-augmented contrastive learning to store normal prototypes; (b) Stage 2 utilizes these memories to generate deviation maps for anomaly scoring.

Stage 1: Representation Learning with Memory

In the first stage, the model learns a "dictionary" of normal prototypes using a memory-augmented contrastive learning setup. Unlike standard contrastive methods, AnoMem incorporates a Modern Hopfield Layer within one branch of a Siamese network. This layer acts as a content-addressable memory that retrieves the closest normal prototype for a given input feature.

A key innovation is the Multi-Scale Spatial Memory. Rather than flattening feature maps, AnoMem treats them as collections of patches. This allows the model to capture local patterns (e.g., textures) in early layers and global structures (e.g., objects) in deeper layers. To prevent memory collapse, a variance regularization loss is applied to ensure the diversity of learned prototypes.

Stage 2: Anomaly Detection and Scoring

Once the memory is populated with normal prototypes, detection becomes a process of identifying "recollection" failures. The model compares an input's feature map to its retrieved version from memory. For normal data, the deviation map (the difference between input and memory) should be minimal. Anomalies, however, will result in high-energy deviation maps because the memory cannot accurately reconstruct unseen patterns.

Experimental Results

AnoMem was evaluated on rigorous benchmarks including CIFAR-10/100, CUB-200, and face anti-spoofing datasets.

Performance comparison (AUC) of AnoMem against baseline methods across different settings, demonstrating its superior performance and unified applicability.

The results demonstrate that AnoMem sets a new performance standard. On the challenging CIFAR-100 dataset, it achieved a 50% relative error reduction compared to previous state-of-the-art one-class methods. Furthermore, in face anti-spoofing tasks, it improved the detection of "Paper Print" attacks by 14%.

One of the most significant advantages of AnoMem is its unified nature. As shown in the results, the model maintains high performance across both one-class and semi-supervised settings without requiring architectural changes—only the final scoring mechanism is adapted.

Conclusion

AnoMem bridges the gap between different AD paradigms by leveraging the power of multi-scale memory and contrastive learning. By focusing on the inability of a "normal" memory to reconstruct anomalous inputs, the framework achieves remarkable discriminative power. Future work will explore the potential of these spatial deviation maps for precise anomaly localization in industrial and medical imaging applications.

Summary updated

BibTeX
@misc{jezequel2022anomaly,
  author = {Loïc Jezequel and Ngoc-Son Vu and Jean Beaudet and Aymeric Histace},
  title = {{Anomaly Detection via Multi-Scale Contrasted Memory}},
  year = {2022},
  eprint = {2211.09041},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2211.09041},
}
Figure