Unsupervised Surface Anomaly Detection with Diffusion Probabilistic Model

Xinyi Zhang, Naiqi Li, Jiawei Li, Tao Dai, Yong Jiang, Shu-Tao Xia

Introduction

In industrial quality control, identifying surface anomalies like scratches, dents, or missing components is critical. However, because anomalous samples are rare, traditional supervised learning is often impractical. Instead, researchers rely on unsupervised anomaly detection, training models exclusively on "normal" (defect-free) data.

The standard approach is reconstruction-based: a model attempts to "repair" an input image into its normal counterpart. A large discrepancy between the input and the reconstruction signals an anomaly. Despite its intuitive appeal, this approach faces three significant challenges:

  1. Reconstruction Fidelity: Standard autoencoders often fail to capture complex structural details.
  2. The "Direct Copy" Problem: High-capacity models may inadvertently reconstruct the anomalies themselves, minimizing the detectable difference.
  3. Misalignment: Harmless variations in texture or position can lead to false positives at the pixel level.

This paper introduces DiffAD, a framework that leverages Latent Diffusion Models (LDMs) to overcome these hurdles and achieve state-of-the-art performance.

Methods

The DiffAD framework consists of two primary components designed to decouple the reconstruction of normal features from the detection of anomalies.

The DiffAD framework architecture, featuring reconstructive and discriminative sub-networks.

Reconstructive Sub-network

Unlike traditional autoencoders, DiffAD utilizes a Latent Diffusion Model (LDM). Diffusion models generate high-quality images by iteratively reversing a noise-addition process. To prevent the model from simply copying anomalies (the "direct copy" problem), the authors introduce Noisy Condition Embedding. By encoding the input into a latent space and adding controlled noise before conditioning the diffusion process, the model is forced to rely on global semantic context to "re-imagine" a clean version of the image rather than replicating local defects.

Discriminative Sub-network

Following reconstruction, a U-Net-based discriminative network compares the original input with the generated "normal" version to produce a pixel-level anomaly mask. To address misalignment and harmless texture variations, the authors employ Interpolated Channels. By creating intermediate feature maps that interpolate between the input and the reconstruction, the network learns to distinguish between "normal diversity" (e.g., natural wood grain shifts) and actual structural defects.

Evaluation and Results

The model was evaluated on the MVTec-AD dataset, a benchmark containing 15 categories (5 textures and 10 objects) with over 5,000 high-resolution images and pixel-precise ground truth.

Quantitative Performance

DiffAD demonstrates superior performance across key metrics:

  • Detection: Achieved an average 98.7% AUROC, surpassing established baselines like DRAEM (98.0%) and PatchCore (98.1%).
  • Localization: The model significantly improves pinpointing accuracy, reaching 98.3% pixel-AUROC and 74.6% Average Precision (AP). The jump in AP from DRAEM’s 68.4% highlights the precision of DiffAD's anomaly masks.

Qualitative Analysis

Visual inspections confirm that DiffAD generates sharp, semantically accurate reconstructions. While competing models often produce blurry or "ghostly" repairs, DiffAD's outputs appear as authentic, defect-free products, facilitating cleaner anomaly detection.

Qualitative results of anomaly localization on various MVTec-AD categories.

Discussion and Future Work

While DiffAD sets a new standard for localization, some limitations remain. The discriminative sub-network can occasionally be distracted by complex background noise in "object" categories. Additionally, while the use of Latent Diffusion Models improves efficiency, the iterative nature of diffusion processes still presents a challenge for real-time industrial deployment.

Future research directions include integrating attention mechanisms within the discriminative sub-network to better isolate objects of interest from irrelevant background variations.

Summary updated

Abstract

Unsupervised surface anomaly detection aims at discovering and localizing anomalous patterns using only anomaly-free training samples. Reconstruction-based models are among the most popular and successful methods, which rely on the assumption that anomaly regions are more difficult to reconstruct. However, there are three major challenges to the practical application of this approach: 1) the reconstruction quality needs to be further improved since it has a great impact on the final result, especially for images with structural changes; 2) it is observed that for many neural networks, the anomalies can also be well reconstructed, which severely violates the underlying assumption; 3) since reconstruction is an ill-conditioned problem, a test instance may correspond to multiple normal patterns, but most current reconstruction-based methods have ignored this critical fact. In this paper, we propose DiffAD, a method for unsupervised anomaly detection based on the latent diffusion model, inspired by its ability to generate high-quality and diverse images. We further propose noisy condition embedding and interpolated channels to address the aforementioned challenges in the general reconstruction-based pipeline. Extensive experiments show that our method achieves state-of-the-art performance on the challenging MVTec dataset, especially in localization accuracy.
BibTeX
@inproceedings{zhang2023unsupervised,
  author = {Xinyi Zhang and Naiqi Li and Jiawei Li and Tao Dai and Yong Jiang and Shu-Tao Xia},
  title = {{Unsupervised Surface Anomaly Detection with Diffusion Probabilistic Model}},
  booktitle = {IEEE/CVF International Conference on Computer Vision},
  year = {2023},
  doi = {10.1109/iccv51070.2023.00624},
}
Figure