Registration based Few-Shot Anomaly Detection

Chaoqin Huang, Haoyan Guan, Aofan Jiang, Ya Zhang, Michael W. Spratling, Yan-Feng Wang

TL;DR

The paper introduces RegAD (Registration-based Anomaly Detection), the first few-shot anomaly detection framework that trains a single, category-agnostic model capable of generalizing to entirely new product categories without any re-training or parameter fine-tuning. By leveraging image registration as a proxy task, RegAD learns to align and compare images, achieving state-of-the-art performance on anomaly detection benchmarks while adapting to new tasks in mere seconds.

What Problem Does This Paper Address?

In industrial quality control, anomaly detection (AD) algorithms are typically trained to spot defects using only "normal" (defect-free) images. However, standard AD methods suffer from two major bottlenecks:

  1. Data Hunger: They require hundreds of normal images per product category to model the normal distribution accurately.
  2. Inflexible Paradigms: They follow a "one-model-per-category" approach. If a factory introduces a new product, a dedicated model must be trained from scratch.

Few-Shot Anomaly Detection (FSAD) attempts to solve the data hunger problem by using only a handful of normal images (e.g., 2, 4, or 8 shots). Yet, prior FSAD methods still adhere to the one-model-per-category paradigm, requiring time-consuming parameter fine-tuning for each new category and failing to exploit structural commonalities across different objects.

RegAD breaks this mold by shifting to a one-model-all-category learning paradigm, mimicking how humans detect anomalies—by directly comparing a suspect object to a known normal reference, regardless of what the object actually is.

Fig. 1. Different from (a) vanilla AD, and (b) existing FSAD methods under the one- model-per-category learning paradigm, the proposed method (c) leverages feature reg- istration as a category-agnostic approach for FSAD, under the one-model-all-category learning paradigm. Trained with aggregated data of multiple categories, the model is directly applicable to novel categories without any parameter fine-tuning, with the only need to estimate the normal feature distribution given the corresponding support set.

Methods

The core idea behind RegAD is to use image registration (the process of transforming different images into a common coordinate system) as a proxy task to learn category-agnostic features.

1. Feature Registration Network

During training, the model is fed pairs of normal images from the same category. Features are extracted using the first three convolutional blocks of a pre-trained ResNet-18. Crucially, a Spatial Transformer Network (STN) block is inserted after each convolutional block to flexibly align the features of the image pair.

To train the network without negative (anomalous) examples and prevent representation collapse, the authors employ a Siamese network structure inspired by SimSiam. One branch passes through a predictor head to maximize the cosine similarity against the other branch, which uses a stop-gradient operation.

Fig. 2. The model architecture of the proposed RegAD. Given paired images from the same category, features are extracted by three convolutional residual blocks each followed by a spatial transformer network. A Siamese network acts as the feature encoder, supervised by a registration loss for feature similarity maximization.

2. Anomaly Inference (No Fine-Tuning)

When a completely unseen target category is introduced at test time:

  • Support Set Augmentation: The few available normal images (the support set) are heavily augmented via rotation, translation, flipping, and graying to expand the reference pool.
  • Distribution Estimation: These augmented images are passed through the fixed registration network. The normal distribution of the registered features is estimated locally at each patch position using a multivariate Gaussian distribution.
  • Anomaly Scoring: Test images are compared against this estimated distribution using the Mahalanobis distance. Any patch that deviates significantly from the statistical norm is flagged as an anomaly.

Datasets

The authors evaluated RegAD on two challenging real-world industrial defect detection benchmarks:

  • MVTec AD: Contains 15 categories (various objects and textures) with 3,629 images for training/validation and 1,725 images for testing. It includes 73 different defect types.
  • MPDD: A newer dataset focusing on painted metal part fabrication across 6 categories. Images feature complex challenges like non-homogeneous backgrounds, variable light intensities, and multiple objects at varying distances and orientations.

Key Insights and Ideas

  • Registration as a Universal Skill: Image alignment is inherently category-agnostic. Once a network learns how to align a screw to a screw, it can easily generalize that alignment skill to a completely unseen object, like a syringe or a piece of leather.
  • Feature-Level vs. Pixel-Level Alignment: Instead of forcing strict pixel-by-pixel registration (which is fragile and overly restrictive), RegAD optimizes for feature-level similarity. This acts as a relaxed constraint that improves robustness against natural intra-class variations.
  • Instantaneous Adaptation: Because the model relies on a statistical estimator (multivariate Gaussian) rather than backpropagation during inference, it adapts to new categories almost instantly.

Key Results

RegAD was evaluated using a leave-one-out cross-validation strategy across 2-shot, 4-shot, and 8-shot scenarios:

  • Superior Accuracy: RegAD outperformed state-of-the-art FSAD methods (like TDG and DiffNet) by 3% to 8% in Area Under the ROC Curve (AUC) on both MVTec and MPDD datasets. For example, on MVTec (8-shot), RegAD achieved a macro-average AUC of 91.2%.
  • Blazing Fast Speed: Traditional FSAD methods require iterative fine-tuning on new categories, taking anywhere from 6 to 25 minutes per category. RegAD completes its adaptation step in just 4.47 seconds—a speedup of over 80x to 300x.
  • Competitive with Full-Data Methods: Remarkably, with only 32 support images, RegAD's performance (94.6% AUC on MVTec) approaches the upper-bound performance of vanilla AD models trained on the entire dataset of hundreds of images.

Limitations and Future Work

While RegAD marks a significant step forward, the authors note a couple of limitations:

  • Diminishing Returns with Large $k$: As the number of available support images ($k$) scales up to 64 or 128, the performance gains begin to saturate. This is likely because the underlying ResNet-18 backbone remains frozen and cannot fully exploit larger volumes of data without fine-tuning.
  • Localization Precision: While excellent at image-level detection, the pixel-level anomaly localization can suffer slight precision losses due to information lost during the inverse transformation operations of the STN modules. Future work could explore high-fidelity coordinate mapping to sharpen defect localization.

Summary updated

BibTeX
@misc{huang2022registration,
  author = {Chaoqin Huang and Haoyan Guan and Aofan Jiang and Ya Zhang and Michael W. Spratling and Yan-Feng Wang},
  title = {{Registration based Few-Shot Anomaly Detection}},
  year = {2022},
  eprint = {2207.07361},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2207.07361},
}
Figure