Glancing at the Patch: Anomaly Localization With Global and Local Feature Comparison

Shenzhi Wang, Liwei Wu, Lei Cui, Yujun Shen

Abstract

This paper introduces an unsupervised framework for anomaly localization that identifies defects by comparing a local image patch to its surrounding context. By training a "Global-Net" to predict what a patch should look like based on its neighborhood, the system can pinpoint anomalies where the actual local features mismatch the predicted global context. The proposed method achieves state-of-the-art performance on the MVTec AD benchmark, particularly in object-based categories.

Introduction

Anomaly localization—the task of segmenting specific defective pixels within an image—is significantly more challenging than simple anomaly detection. A major gap in existing research is that most models either analyze the image as a whole, missing fine-grained local details, or examine patches in isolation.

Looking at a patch in isolation is problematic because an object might appear "normal" on its own but constitute an anomaly due to its context (e.g., a green wire where a red one should be). To address this, the authors propose a model that understands the relationship between a local area and its global context, treating anomaly detection as a mismatch between expectation and reality.

Methodology

The framework utilizes a patch-based approach centered around two primary networks and two specialized detection heads:

  1. Local-Net: A lightweight network distilled from a pre-trained ResNet-18, responsible for extracting features from a specific image patch.
  2. Global-Net: This network analyzes the "surrounding" area of the patch. It employs Partial Convolutions to ensure it cannot "see" the patch itself, forcing it to infer the patch's features based solely on the context.
  3. Inconsistency Anomaly Detection (IAD) Head: This calculates the distance between the local feature and the global feature. If the context suggests a specific structure should be present but the Local-Net observes something else, the IAD score increases.
  4. Distortion Anomaly Detection (DAD) Head: A trainable classifier designed to identify subtle structural defects. During training, synthetic "stains" are added to normal patches to teach the DAD head to distinguish subtle distortions from clean patches.
Overview of the proposed anomaly localization framework, illustrating the dual-head architecture (IAD and DAD) and the patch-based inference process.

At inference time, the model performs a raster scan across the image, generating scores for every patch. These are then aggregated into a high-resolution anomaly map using Inverse Distance Weighted (IDW) interpolation.

Experimental Results

The researchers evaluated their model on the MVTec AD dataset, the gold standard for industrial anomaly detection containing 15 categories of objects and textures. They also tested versatility on CIFAR-10 in a one-class classification setting.

Key Findings

  • State-of-the-Art Performance: On the MVTec AD dataset, the proposed method achieved a 96.1% PRO (Per-Region Overlap) score, significantly outperforming previous benchmarks like Teacher-Student networks (91.4%).
  • Texture vs. Object: The model proved exceptionally strong on "Object" categories (e.g., Transistors and Screws), achieving near-perfect scores (99.9% and 100% respectively) due to its reliance on precise spatial context.
  • Qualitative Superiority: Visual results demonstrate the model's ability to accurately segment tiny cracks and subtle color shifts that traditional reconstruction-based models (like Auto-Encoders) often blur.
Qualitative results on the MVTec AD dataset, comparing original images, ground-truth masks, and the model's generated score maps across various categories.

Discussion and Limitations

The "aha moment" of this research is treating anomaly detection as a mismatch between expectation and reality. Forcing the Global-Net to "imagine" the patch allows the model to detect "logical" anomalies that reconstruction models often miss. The use of partial convolutions is a critical architectural choice that prevents the Global-Net from "cheating" by peeking at the center pixels.

However, some limitations remain. The current model uses a fixed patch size, which may be sub-optimal for anomalies that are either extremely large or microscopic. Future work could incorporate a multi-scale approach or feature pyramids. Additionally, the DAD head's reliance on synthetic training data may not perfectly capture the complexity of all real-world physical degradations.

Conclusion

By comparing local features with global context through a dual-head architecture, this framework provides a robust solution for unsupervised anomaly localization. It effectively bridges the gap between global understanding and local precision, setting a new standard for industrial inspection tasks.

Summary updated

BibTeX
@inproceedings{wang2021glancing,
  author = {Shenzhi Wang and Liwei Wu and Lei Cui and Yujun Shen},
  title = {{Glancing at the Patch: Anomaly Localization With Global and Local Feature Comparison}},
  booktitle = {IEEE/CVF Conference on Computer Vision and Pattern Recognition},
  year = {2021},
  doi = {10.1109/cvpr46437.2021.00032},
}
Figure