Memory Banks for Visual Anomaly Detection

19 concepts18 papers

Traditional unsupervised anomaly detection relied heavily on generative models like Autoencoders and Generative Adversarial Networks (GANs). The underlying hypothesis was simple: train a network to reconstruct normal images, and it will naturally fail when tasked with reconstructing an anomaly. However, deep neural networks are notoriously powerful generalizers, often reconstructing anomalous textures and defects surprisingly well. This "shortcut" problem frequently causes generative models to miss the exact anomalies they were built to detect.

To bypass this limitation, a powerful paradigm shift has emerged: instead of trying to reconstruct normality, models can simply remember it. This is the core intuition behind memory-bank feature retrieval. As surveyed by Guoyang Xie et al., these memory-augmented systems store a representative gallery of nominal (normal) feature vectors during training. During inference, the model determines the degree of abnormality purely by calculating the geometric distance between the features of a test sample and the closest entries in the stored bank.

The Geometry of Normality

Why does this non-parametric approach work so well? It leverages the fact that deep vision models create highly descriptive latent spaces where semantic similarities translate directly to geometric proximity. This holds true whether the features are extracted from models pre-trained on massive natural image datasets or even mathematically generated synthetic data like fractals, as demonstrated by Cynthia I. Ugwu et al..

The standard memory-bank pipeline operates in three distinct phases:

  1. Feature Extraction: An input image is broken down into local patches, and a deep network extracts high-dimensional feature embeddings for each patch. For instance, Mike Laszkiewicz et al. show that leveraging a frozen foundation model like DINOv2 provides exceptionally rich patch features out-of-the-box, enabling strong anomaly detection even in few-shot scenarios with very few reference images.
  2. Memory Bank Storage: During training, patch features from entirely normal samples are collected into a database, establishing a baseline of normal appearance.
  3. Nearest-Neighbor Retrieval: At test time, patch features from a query image are compared against the memory bank. As explained by Hanshi Sun et al. and Akshatha Arodi et al., the anomaly score is determined by the distance between the query feature and its nearest neighbors in the nominal feature space.

If a patch's feature vector is geometrically isolated from the stored normal distribution, it is flagged as anomalous. Because this comparison happens patch-by-patch, the system can pinpoint exactly where a defect is located. This property is highly effective for localizing structural defects, a capability utilized by Vincent Wahyudi et al. to detect cracks and contamination in industrial containers.

Overcoming the Storage Bottleneck

While conceptually straightforward, storing every single patch feature from thousands of high-resolution training images quickly becomes computationally intractable. To make this approach viable for real-world deployment, the memory bank must be compressed without losing its coverage of the normal distribution.

One prominent solution is coreset selection. As implemented by Jiaqi Liu et al. for 3D point cloud anomaly detection, a coreset algorithm selects a minimal subset of feature vectors that spans the same geometric space as the full dataset. This drastically reduces the memory footprint while maintaining the fidelity of nearest-neighbor searches.

Another solution is prototypical aggregation, where individual patch features are clustered or averaged into centralized "prototypes." Xincheng Yao et al. simplify the memory bank by averaging patch-level features from the normal training set to serve as a stable global reference. Taking this further, Sungwook Lee et al. utilize a compressed, scalable memory bank optimized via a coupled-hypersphere loss. This loss explicitly shapes the target feature distribution, preventing the model from overestimating normality and ensuring high efficiency even on massive industrial datasets.

Context, Motion, and Adaptation

The memory-bank paradigm is highly flexible and extends naturally beyond static, isolated image patches to handle complex contextual and temporal relationships.

Contextual and Logical Anomalies

Standard patch matching can fail when an object is normal in isolation but anomalous due to its surroundings (e.g., a person running in a restricted area). To capture these relationships, Shengyang Sun et al. maintain a library of prototypical normal features that represent diverse patterns of expected behavior in a hierarchical latent space, allowing the model to resolve scene-dependent anomalies.

Spatio-Temporal Modeling

In video anomaly detection, the memory bank must store motion patterns alongside appearance features. Zhonghua Peng et al. maintain a memory bank of prototypical normal behaviors to detect anomalous driving actions, while Zhangxun Li et al. combine a learnable memory bank with state-space models (Mamba) to efficiently reconstruct and score spatial-temporal normality. To prevent background noise from polluting these representations, Che Sun et al. explicitly disentangle and store only "event-relevant" factors in their memory module.

Test-Time Adaptation

Memory banks can also function dynamically during deployment. Hongzheng Yang et al. demonstrate that a memory bank storing recently processed feature-prediction pairs can be used to estimate real-time distribution shifts. By measuring the discrepancy between a current prediction and its retrieved neighbors, the system dynamically tunes its learning rate to adapt to cross-domain medical imaging variations on-the-fly.

Conclusion

Memory-bank feature retrieval succeeds because it replaces a difficult optimization problem—training a generative model to perfectly bound normality—with a straightforward geometric retrieval problem. As confirmed by comparative studies like the one by Manuel Barusco et al., while reconstruction methods still hold value in specific imaging domains, feature-comparison memory banks offer unparalleled localization capabilities and deployment simplicity across diverse industrial and medical applications.

Key Foundational Work

Learning Event-Relevant Factors for Video Anomaly Detection (2023) — contributed 2 concept elements to this direction.
Hierarchical Semantic Contrast for Scene-aware Video Anomaly Detection (2023) — contributed 1 concept elements to this direction.
BMAD: Benchmarks for Medical Anomaly Detection (2023) — contributed 1 concept elements to this direction.
History & citationVersion 1 · 2026-10-04

Current · Permanent link

View frozen version 1

Cite this direction

Latest version (a living page):

@misc{lacuna_memory_bank_feature_retrieval_65fa35c0,
  title = {memory-bank feature retrieval},
  author = {{Lacuna}},
  howpublished = {Lacuna research direction},
  year = {2026},
  url = {https://lacuna.tiptreesystems.com/direction/memory-bank-feature-retrieval/rdr_65fa35c0c3ca4667a3bb963e517d1385},
  note = {Latest version of a living research direction; cite a version for a fixed text. Accessed 2026-11-23},
}

This exact version (version 1, frozen text):

@misc{lacuna_memory_bank_feature_retrieval_65fa35c0_v1,
  title = {memory-bank feature retrieval},
  author = {{Lacuna}},
  howpublished = {Lacuna research direction},
  year = {2026},
  url = {https://lacuna.tiptreesystems.com/direction/memory-bank-feature-retrieval/rdr_65fa35c0c3ca4667a3bb963e517d1385/v/1},
  note = {Version 1, frozen 2026-10-04. Accessed 2026-11-23},
}

See something wrong? Report a mistake