A Prototype-Based Neural Network for Image Anomaly Detection and Localization

Chao Huang, Zhao Kang, Hong Wu

TL;DR

ProtoAD is a novel framework for image anomaly detection that eliminates the need for a traditional training phase by using non-parametric clustering to identify "prototypes" of normal image patches. By implementing prototype matching as a $1 \times 1$ convolutional layer, the authors achieve state-of-the-art accuracy with inference speeds exceeding 72 FPS—significantly faster than existing high-performance methods like PatchCore.

What Problem Does This Paper Address?

In industrial settings, detecting and localizing defects (anomalies) is critical. However, anomalies are rare, meaning models must usually learn from "normal" samples only. Current approaches generally fall into two camps:

  1. Reconstruction-based: These try to rebuild an image; if they fail, the area is flagged as an anomaly. These are often slow and difficult to train.
  2. Out-of-Distribution (OOD) based: These compare image patches against a "memory bank" of normal features.

While OOD methods like PatchCore are highly accurate, they often struggle with inference speed and memory overhead because they have to search through massive banks of features for every pixel. The authors of this paper sought to bridge this gap: how can we maintain the high accuracy of patch-based comparison while making it fast enough for real-time industrial pipelines?

Methods

The authors propose ProtoAD, which follows a three-step pipeline:

  1. Feature Extraction: They use a Wide-ResNet50 backbone pre-trained on ImageNet. Crucially, they only use features from the first three stages (low-to-mid level). High-level features are often too biased toward specific ImageNet categories (like "dogs" or "cars") to be useful for finding a scratch on a metal nut.
  2. Prototype Learning (The "Training" Phase): Instead of keeping every single normal patch feature, they use a clustering algorithm called FINCH (First Integer Neighbor Clustering Hierarchy). FINCH is "parameter-free," meaning it doesn't require the user to guess the number of clusters ($k$) beforehand. It groups similar normal patches into "prototypes."
  3. The ProtoAD Network: This is the clever part. They realize that the cosine similarity between a test patch and a prototype is mathematically equivalent to a dot product (if features are $L2$-normalized). They build a simple neural network where the kernels of a $1 \times 1$ convolutional layer are the prototypes themselves.

To find an anomaly, the image passes through the feature extractor, gets normalized, and hits the $1 \times 1$ conv layer. A "channel max-pooling" operation then identifies the closest prototype for each patch. If the similarity is low, the area is marked as anomalous.

Datasets

The model was evaluated on two gold-standard industrial benchmarks:

  • MVTec AD: 15 categories (10 objects like "Transistor" and 5 textures like "Leather") containing 5,354 high-resolution images.
  • BTAD (BeanTech Anomaly Detection): A newer dataset featuring 2,830 images across 3 industrial products.

Key Insights and Ideas

  • Convolution as a Search Engine: By turning the "nearest neighbor search" into a $1 \times 1$ convolution, the authors move the heaviest computational load onto highly optimized GPU kernels. This is why the model is so much faster than its predecessors.
  • Parameter-Free Clustering: Using FINCH avoids the "tedious parameter tuning" required by K-Means. It allows the model to adapt the number of prototypes based on the complexity of the specific object or texture being inspected.
  • Feature Hierarchy Matters: The paper reinforces the idea that for industrial anomalies (which are often structural or textural), mid-level features are superior to the abstract, high-level features used for general image classification.

Key Results

ProtoAD strikes an impressive balance between precision and speed:

  • Inference Speed: It reaches 72.45 FPS, making it roughly 1.2x faster than PaDiM and 2.7x to 9.5x faster than PatchCore (depending on the coreset size).
  • Localization Accuracy: On the MVTec AD dataset, it achieved a pixel-level AUROC of 97.2% and a PRO-score (which weights small and large anomalies equally) of 93.6%, outperforming almost all other OOD-based methods except PatchCore.
  • Detection Accuracy: On the BTAD dataset, it achieved the best image-level AUROC (94.0%) among all compared methods.

Limitations and Future Work

While ProtoAD is highly efficient, there are a few areas for consideration:

  • Performance Gap: In some specific "object" categories on MVTec AD, it still slightly trails PatchCore in pixel-level AUROC (97.1% vs 98.4%).
  • Prototype Thresholding: The authors chose a fixed stopping criterion for clustering (10,000 clusters) to balance speed and accuracy. While this worked well, an even more adaptive approach might yield better results for extremely simple or extremely complex textures.
  • End-to-End Integration: The authors note that because the model is essentially just a standard CNN at inference time, it is much more "elegant" to deploy in existing computer vision pipelines than methods requiring external memory banks or complex nearest-neighbor libraries.

Summary updated

BibTeX
@inproceedings{huang2024prototype,
  author = {Chao Huang and Zhao Kang and Hong Wu},
  title = {{A Prototype-Based Neural Network for Image Anomaly Detection and Localization}},
  booktitle = {Neural Process. Lett},
  year = {2024},
  url = {https://openreview.net/forum?id=9x29H2d8rd},
}

Loading related content...

Figure