Unsupervised Visual Defect Detection with Score-Based Generative Model

Yapeng Teng, Haoyang Li, Fuzhen Cai, Ming Shao, Siyu XiaarXiv 2022 · OpenReview

TL;DR

This paper introduces Score-DD, a novel unsupervised method for detecting visual defects in industrial products. It leverages score-based generative models to identify anomalies by analyzing how reconstructed images deviate from the original, outperforming previous methods on challenging benchmarks.

What Problem Does This Paper Address?

Visual Defect Detection (VDD) is a crucial but challenging problem in industrial applications. The core difficulty lies in the scarcity and difficulty of collecting defect samples, making traditional supervised learning approaches impractical. Existing unsupervised methods, like Autoencoders (AEs) and Generative Adversarial Networks (GANs), often struggle with high-dimensional image data, leading to blurred reconstructions or failure to effectively highlight subtle defects. This paper aims to bridge this gap by proposing an unsupervised VDD framework that effectively detects and localizes defects without requiring any defect samples during training.

Methods

The proposed method, Score-DD, is built upon recent advancements in score-based generative models, which use stochastic differential equations (SDEs) to iteratively denoise data and synthesize realistic images. The key idea is that anomalous data points (defects) reside in low-probability regions of the normal data distribution.

Here's a breakdown of their approach:

  • Score-Based Generative Models: The foundation is a score-based generative model trained solely on normal (defect-free) images. These models learn to predict the gradient of the log probability density of the data distribution (the "score").
  • Reconstruction and Defect Detection: When a noisy version of an image is fed through the reverse diffusion process (denoising), the model attempts to reconstruct it. The core insight is that defects, being in low-density regions, will be treated differently during this process compared to normal pixels.
  • Whole-Score vs. Self-Score:
    • Whole-score ($s_w(x, t)$): This metric, derived from the score function, guides the denoising process towards the high-density regions of the normal data distribution. It's used to reconstruct the image towards a "normal" state.
  • Self-score ($s_e(x, t)$): This is a related score that helps approximate the true trajectory of the original data.
  • The difference between the whole-score reconstruction and the self-score reconstruction is used as the anomaly score. This divergence highlights areas where the reconstruction process behaves differently, indicating potential defects.
  • T Scales Approach: To accelerate inference and improve robustness, Score-DD introduces a "T scales" approach. Instead of performing a full, lengthy denoising process for a single time step, it samples from a set of different time steps ($t$) and uses the resulting feature maps. This allows for a more efficient and potentially more accurate anomaly map generation by capturing information at various stages of the denoising process.

Datasets

The paper evaluates Score-DD on several standard datasets:

  • MVTec AD dataset: A widely used benchmark for unsupervised anomaly detection, containing 5354 high-resolution images across 10 object and 5 texture categories.
  • BeanTech AD dataset: An industrial dataset with 2540 high-resolution images of three products.
  • MNIST: A dataset of handwritten digits, used for demonstrating the method's capabilities on simpler data.

Key Insights and Ideas

  • Score as a Metric for VDD: The paper argues that using the score function (gradient of the log probability density) is a more reliable metric for VDD than traditional reconstruction loss. This is because reconstruction-based methods can sometimes alter normal pixels slightly, making direct pixel-wise comparison unreliable. The score, by directly probing the data distribution's density, offers a more robust indicator of anomalies.
  • Defects as Low-Density Regions: The fundamental assumption that defects reside in low-probability regions of the normal data distribution is key. This allows the score-based model to effectively differentiate between normal and anomalous areas.
  • T Scales for Efficiency and Effectiveness: The "T scales" approach is a clever way to balance the trade-off between reconstruction fidelity and computational cost. By leveraging information from multiple time steps, it achieves faster inference without sacrificing significant performance, and potentially even improving it by capturing diverse semantic information.
  • Unsupervised Generalization: The method's ability to generalize to VDD tasks without requiring any defect samples during training is a significant advantage, making it practical for real-world industrial scenarios.

Key Results

  • State-of-the-Art Performance: Score-DD achieves state-of-the-art (SOTA) results on the MVTec AD dataset, reaching 98.24% image-level AUC and 97.78% pixel-level AUC.
  • Competitive Results on Other Datasets: The method also demonstrates strong performance on the BeanTech AD dataset, achieving 93.4% image-level AUC and 97.1% pixel-level AUC, and competitive results on MNIST.
  • Outperforms Existing Methods: Score-DD surpasses many existing unsupervised VDD methods, including AE-based and GAN-based approaches, and is competitive with methods that rely on pre-trained models or pseudo-defect generation.
  • Efficiency Improvement: The T scales technique significantly reduces inference time compared to methods requiring full diffusion processes.

Limitations and Future Work

  • Assumption Dependency: The method's effectiveness relies on the assumption that anomalous data lies in low-density regions of the normal data distribution. This might limit its applicability in some broader Anomaly Detection (AD) settings where anomalies might not strictly adhere to this principle.
  • Fixed Feature Map Selection: The current approach uses fixed feature maps, which might not be optimally adapted to every image. The authors suggest that an adaptive feature map selection strategy could be beneficial.
  • Future Directions: The authors propose extending the method with auxiliary category information or classifiers for improved performance in complex AD scenarios. They also suggest exploring self-supervised or semi-supervised techniques to further enhance feature map selection and adapt the model to different images.

Summary updated

Abstract

Anomaly Detection (AD), as a critical problem, has been widely discussed. In this paper, we specialize in one specific problem, Visual Defect Detection (VDD), in many industrial applications. And in practice, defect image samples are very rare and difficult to collect. Thus, we focus on the unsupervised visual defect detection and localization tasks and propose a novel framework based on the recent score-based generative models, which synthesize the real image by iterative denoising through stochastic differential equations (SDEs). Our work is inspired by the fact that with noise injected into the original image, the defects may be changed into normal cases in the denoising process (i.e., reconstruction). First, based on the assumption that the anomalous data lie in the low probability density region of the normal data distribution, we explain a common phenomenon that occurs when reconstruction-based approaches are applied to VDD: normal pixels also change during the reconstruction process. Second, due to the differences in normal pixels between the reconstructed and original images, a time-dependent gradient value (i.e., score) of normal data distribution is utilized as a metric, rather than reconstruction loss, to gauge the defects. Third, a novel $T$ scales approach is developed to dramatically reduce the required number of iterations, accelerating the inference process. These practices allow our model to generalize VDD in an unsupervised manner while maintaining reasonably good performance. We evaluate our method on several datasets to demonstrate its effectiveness.
BibTeX
@misc{teng2022unsupervised,
  author = {Yapeng Teng and Haoyang Li and Fuzhen Cai and Ming Shao and Siyu Xia},
  title = {{Unsupervised Visual Defect Detection with Score-Based Generative Model}},
  year = {2022},
  eprint = {2211.16092},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2211.16092},
}
Figure