AMI-Net: Adaptive Mask Inpainting Network for Industrial Anomaly Detection and Localization

Wei Luo, Haiming Yao, Wenyong Yu, Zhengyong LiarXiv 2024

TL;DR

AMI-Net is a high-speed, unsupervised anomaly detection framework that uses an adaptive mask generator to "hide" potential defects from an inpainting network. By forcing a Vision Transformer to reconstruct these masked areas using only normal global context, the system effectively suppresses the reconstruction of defects, leading to state-of-the-art localization accuracy at real-time speeds (11.48 ms).

What Problem Does This Paper Address?

In industrial quality control, finding defects is hard because they are rare and unpredictable. Most modern systems use unsupervised reconstruction: they train on thousands of "normal" images, learning to rebuild them perfectly. The theory is that when an anomalous image (a scratch, a dent, a missing part) comes in, the model will fail to reconstruct the defect, creating a high "reconstruction error" that signals an anomaly.

However, neural networks are too good at generalizing. Standard Autoencoders (AEs) often learn to reconstruct the defects themselves, resulting in low error and missed detections. Previous "mask-based" attempts tried to fix this by randomly hiding parts of the image and asking the network to fill them in (inpainting). But random masks often miss the defect entirely or require slow, iterative testing to be effective.

Comparison of vanilla reconstruction vs. random masking vs. AMI-Net's adaptive approach.

Methods

AMI-Net introduces three major innovations to solve the "perfect reconstruction" problem:

  1. Feature-Level Reconstruction: Instead of trying to predict raw pixels, AMI-Net reconstructs multi-scale semantic features extracted by a pre-trained CNN (WideResNet50). Features are more discriminative than raw pixels, making it easier to separate "normal" from "abnormal."
  2. Adaptive Mask Generator: This is the core "brain" of the system. During testing, it uses cluster tokens—learned representations of normal patterns—to identify regions that don't fit the "normal" profile. It then dynamically generates a mask to hide these suspicious regions.
  3. ViT-based Inpainting: A Vision Transformer (ViT) takes the partially masked features and restores them. Because ViTs use global self-attention, they can look at the entire "normal" part of the object to figure out what should be in the masked (defective) area.
The overall architecture of AMI-Net showing the training and testing phases.

Datasets

The authors evaluated AMI-Net on two standard industrial benchmarks:

  • MVTec AD: The industry standard, containing 15 categories ranging from simple textures (carpet, leather) to complex objects (transistor, cable).
  • BTAD: A challenging dataset focused on industrial textures with high-resolution pixel-level localization requirements.

Key Insights and Ideas

  • Adaptive beats Random: By specifically masking regions that look anomalous, the model is forced to replace defects with "normal" content, maximizing the reconstruction error precisely where it's needed.
  • Position Matters: For objects like transistors or screws, a defect might not be a "weird texture" but a normal part in the wrong place. The authors found that adding positional embeddings to their clustering process was vital for detecting these "global" structural anomalies.
  • Speed is King: Unlike iterative masking methods that might take hundreds of milliseconds, AMI-Net's single-pass adaptive masking allows it to run at ~87 FPS, making it viable for high-speed assembly lines.
The importance of positional information for detecting global structural defects.

Key Results

  • Accuracy: On MVTec AD, AMI-Net achieved a 99.0% image-level AUROC and a 98.2% pixel-level AUROC, reaching a perfect 100% on categories like Leather, Wood, and Bottle.
  • Generalization: It outperformed the popular PatchCore method on the BTAD dataset (95.1% vs 90.0% image AUROC), suggesting it generalizes better to different types of industrial data.
  • Efficiency: With an inference time of 11.48 ms, it is over 4x faster than PatchCore, while maintaining comparable or superior accuracy.
  • Unified Modeling: In a "one-for-all" setting (one model for all 15 MVTec categories), it set a new state-of-the-art with 97.2% image AUROC.

Limitations and Future Work

Despite its strengths, AMI-Net has a few hurdles:

  • Subtle Defects: It still struggles with extremely low-contrast anomalies or defects that look nearly identical to the background texture.
  • Noise Sensitivity: Minor background noise can occasionally be mistaken for a defect, leading to false positives.
  • Future Direction: The authors plan to explore "semi-supervised" extensions where a small number of known defect samples can be used to further refine the adaptive mask generator's ability to discriminate between noise and actual damage.

Summary updated

BibTeX
@misc{luo2024ami,
  author = {Wei Luo and Haiming Yao and Wenyong Yu and Zhengyong Li},
  title = {{AMI-Net: Adaptive Mask Inpainting Network for Industrial Anomaly Detection and Localization}},
  year = {2024},
  eprint = {2412.11802},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2412.11802},
}
Figure