DiAD: A Diffusion-based Framework for Multi-class Anomaly Detection

Haoyang He, Jiangning Zhang, Hongxu Chen, Xuhai Chen, Zhishan Li, Xu Chen 0024, Yabiao Wang, Chengjie Wang, Lei XiearXiv 2023 · DOI

Introduction

In industrial quality control, Anomaly Detection (AD) is a critical task that involves identifying defects such as scratches, missing components, or structural irregularities. The prevailing paradigm for AD relies on reconstruction: a model is trained exclusively on "normal" data to learn the underlying distribution of defect-free samples. During inference, the model attempts to reconstruct the input image. Discrepancies between the original image and its reconstructed "normal" version highlight potential anomalies.

While effective in single-class settings, traditional reconstruction models struggle with the "multi-class" challenge—training a single model to detect anomalies across diverse object categories—and the "scale dilemma," where defects range from microscopic texture flaws to large structural absences. This paper introduces DiAD (Diffusion-based Anomaly Detection), a framework leveraging latent diffusion models to address these limitations and set a new state-of-the-art in multi-class anomaly detection.

The Multi-class Challenge and the Scale Dilemma

Existing AD methods face two primary hurdles when scaled to real-world factory environments:

  1. Category Confusion: Standard diffusion models, such as DDPM, often lose the "identity" of an object during the denoising process. When noise is added to a defective nut, the model might reconstruct it as a normal bolt, leading to false positives or inaccurate localization because the reconstruction no longer matches the original category.
  2. The Scale Dilemma: Anomalies are scale-dependent. A scratch on leather requires fine-grained texture analysis, while a missing part on a PCB requires global structural understanding. Most models struggle to balance these two scales simultaneously.

The DiAD Framework

DiAD overcomes these hurdles through a three-part architecture designed to preserve semantic integrity and handle multi-scale features.

1. Semantic-Guided (SG) Network

To prevent category confusion, DiAD introduces a Semantic-Guided network that operates in parallel with a pre-trained Stable Diffusion (SD) denoising network. The SG network uses the original input image as a continuous reference, ensuring that the denoising process is conditioned on the specific category and global structure of the object. This ensures that a reconstructed screw remains a screw, even after the diffusion process "cleans" the anomalous regions.

2. Spatial-aware Feature Fusion (SFF) Block

The SFF block is the core mechanism for resolving the scale dilemma. It integrates high-scale semantic information into low-scale detail layers, allowing the model to remain "texture-aware" for small defects and "object-aware" for large-scale structural changes. By fusing these features, DiAD can accurately reconstruct both tiny surface scratches and major missing components.

3. Feature-space Anomaly Extraction

Rather than relying on simple pixel-wise subtraction, which is prone to noise, DiAD utilizes a pre-trained feature extractor (e.g., ResNet). Both the original and the reconstructed images are passed through this extractor. The framework then calculates the cosine similarity between their feature maps across multiple scales to generate a precise anomaly map, identifying exactly where the input deviates from the learned "normal" distribution.

Experimental Evaluation

The authors evaluated DiAD across four diverse benchmarks to test its robustness and versatility:

  • MVTec-AD: The industry standard for industrial AD.
  • VisA: A challenging dataset featuring complex structures and multiple object instances.
  • MVTec-3D: Testing scalability to 3D-derived data.
  • Medical Datasets (BraTS2021, BTCV, LiTs): Demonstrating the framework's ability to identify tumors and lesions in healthcare applications.

Performance Highlights

DiAD achieved significant performance gains over previous state-of-the-art (SOTA) methods:

  • MVTec-AD: Attained 96.8% AUROC for anomaly localization and 97.2% AUROC for detection in a unified multi-class setting.
  • Comparison to Diffusion SOTA: DiAD outperformed previous diffusion-based models like AnoDDPM by a pixel-level AUROC margin of 20.6%.
  • Comparison to Unified Models: It surpassed non-diffusion unified models like UniAD, particularly in Average Precision (AP), which is a more rigorous measure of localization accuracy.

Key Insights

  • Denoising as Targeted Reconstruction: Unlike generative models that create images from scratch, DiAD treats the diffusion process as a targeted "clean-up" tool. It adds a controlled amount of noise to obscure anomalies and then uses the learned distribution of normalcy to fill those gaps accurately.
  • Normalization Strategy: The research found that standard Batch Normalization (BN) is detrimental in multi-class settings as it tends to blur the unique characteristics of different categories. Switching to Instance Normalization (IN) and SiLU activation functions provided a significant boost in performance.

Conclusion and Future Work

DiAD represents a major step forward in making anomaly detection practical for complex, multi-category industrial environments. While highly effective, the authors noted that the model can occasionally produce false positives due to the high sensitivity of pre-trained feature extractors to background noise or complex shadows.

Future research will explore integrating multi-modal assistance—such as text prompts or 3D data—to help the model better distinguish between benign background variations and actual defects. Additionally, scaling the framework to larger foundation models may further enhance the reconstruction quality for increasingly complex industrial scenes.

Summary updated

BibTeX
@misc{he2023diad,
  author = {Haoyang He and Jiangning Zhang and Hongxu Chen and Xuhai Chen and Zhishan Li and Xu Chen and Yabiao Wang and Chengjie Wang and Lei Xie},
  title = {{DiAD: A Diffusion-based Framework for Multi-class Anomaly Detection}},
  year = {2023},
  eprint = {2312.06607},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2312.06607},
}
Figure