Patch-aware Vector Quantized Codebook Learning for Unsupervised Visual Defect Detection

Qisen Cheng, Shuhui Qu, Janghwan Lee

TL;DR

PVQAE (Patch-aware Vector Quantized Autoencoder) introduces a dynamic way to allocate representation capacity for industrial anomaly detection. By learning to use high-resolution codes only for complex image regions and low-resolution codes for simple ones, the model creates a "memory of normality" that effectively flags defects by their inability to be reconstructed within the learned "budget."

What Problem Does This Paper Address?

In unsupervised visual defect detection, we usually train models on "normal" data so they can identify anomalies as anything that deviates from the norm. A common tool for this is the Autoencoder, which tries to reconstruct the input image.

However, researchers face a "Goldilocks" dilemma regarding representation capacity:

  1. Too little capacity: The model can't even reconstruct normal images well, leading to false positives.
  2. Too much capacity: The model becomes too good at reconstructing everything, including the defects (a phenomenon called "mode collapse"), making anomalies invisible.

Existing methods often apply a uniform resolution across the entire image, which is inefficient. A smooth surface on a metal part needs very little data to describe, while a complex logo or texture needs much more.

Methods

The authors propose PVQAE, which extends the Vector Quantized Variational Autoencoder (VQ-VAE) framework with three novel components:

  • Multi-resolution Dynamic Code Allocation: Instead of a fixed grid, a Dynamic Routing Module selects the optimal resolution for each image patch from a hierarchy of candidates. It assigns "fine" codes to information-rich areas and "coarse" codes to simple regions.
  • Progressive Budget Learning: To prevent the model from simply using high resolution everywhere, the authors introduce a budget loss. They use Discrete Wavelet Transform (DWT) entropy to estimate the "context richness" of a patch. If a patch is simple, the model is penalized more heavily for using high-resolution codes.
  • Normal Budget Priors: The model doesn't just learn to reconstruct; it learns the spatial pattern of code usage. A Budget Prior Transformer is trained to predict the expected resolution for each patch. During inference, if a patch requires a significantly different "budget" than what the Transformer predicts, it’s a strong signal that a defect is present.

Datasets

The model was evaluated on three standard industrial "cold-start" (unsupervised) benchmarks:

  • MVTecAD: 15 categories of industrial objects and textures (5,354 images).
  • BTAD (Bean Tech Anomaly Dataset): 3 industrial products (2,830 images).
  • MTSD (Magnetic Tile Surface Defect): Focused specifically on magnetic tile images.

Key Insights and Ideas

  • The "Budget" is a Feature: One of the most clever ideas here is treating the amount of information used to describe a patch as an anomaly indicator. If a normally smooth area suddenly "demands" a high-resolution code to be reconstructed, it’s likely because a crack or scratch has added unexpected complexity.
  • Efficiency through Sparsity: By not forcing high-resolution latent variables on every pixel, the model focuses its "attention" on the parts of the object that actually define its normality.
  • Solving Mode Collapse via Constraints: By forcing the model to be "economical" during training, it loses the ability to reconstruct the "weird" details of a defect during testing, thereby increasing the reconstruction error and making the defect easier to spot.

Key Results

PVQAE achieved state-of-the-art (SOTA) or competitive results across all tested datasets:

  • MVTecAD: Achieved high Image-level and Pixel-level AUROC (Area Under the Receiver Operating Characteristic), outperforming previous VQ-based methods like HVQ-Trans.
  • Qualitative Superiority: Visualizations show that PVQAE produces much "cleaner" heatmaps than standard VQ-VAEs. While a standard VQ-VAE might show noisy signals across the whole image, PVQAE’s heatmaps are highly concentrated on the actual defect (e.g., a tiny crack on a pill or a smudge on a hazelnut).
  • Ablation Success: The authors found that a linear schedule for the budget weight ($\lambda$) worked best—starting at zero to let the model learn basic reconstruction first, then gradually increasing the pressure to be efficient.

Limitations and Future Work

While the paper demonstrates strong results, a few areas remain for exploration:

  • Complexity: The architecture is multi-stage, involving a VQ-VAE, a Dynamic Routing Module, and a Transformer. This might make it more difficult to tune compared to simpler "memory bank" methods like PatchCore.
  • Data Requirements: The authors had to combine the BTAD and MTSD datasets for training due to limited sample sizes, suggesting the "Budget Prior Transformer" might require a certain volume of data to learn spatial patterns effectively.
  • Real-time Constraints: While the paper mentions efficiency in representation, it doesn't explicitly detail the inference latency, which is a critical factor for high-speed assembly line integration.

Summary updated

BibTeX
@inproceedings{cheng2024patch,
  author = {Qisen Cheng and Shuhui Qu and Janghwan Lee},
  title = {{Patch-aware Vector Quantized Codebook Learning for Unsupervised Visual Defect Detection}},
  booktitle = {ICTAI},
  year = {2024},
  doi = {10.1109/ictai62512.2024.00088},
}
Figure