Unsupervised Anomaly Detection via Masked Diffusion Posterior Sampling

Di Wu, Shicai Fan, Xue Zhou, Yu Li, Yuzhong Deng, Jianxiao Zou, Baihong Lin, Yingzong Liu, Jianhui Mei, Maolei Fu, Yun Ye, Zhujin Liang, Yi Shan, Dalong Du

Abstract

Unsupervised Anomaly Detection (UAD) is critical for industrial quality control, yet existing reconstruction-based methods often struggle with blurry outputs or the "identical shortcut" problem. This paper introduces Masked Diffusion Posterior Sampling (MDPS), a novel framework that utilizes diffusion models to reconstruct normal images from anomalous inputs. By formulating the task as a Bayesian posterior sampling problem with a masked observation model, MDPS preserves fine-grained textures while effectively removing defects. Evaluated on the MVTec AD and BTAD datasets, MDPS demonstrates superior performance in both image-level and pixel-level anomaly detection compared to existing state-of-the-art methods.

Introduction

Unsupervised Anomaly Detection (UAD) involves identifying deviations from a learned "normal" distribution without access to anomalous samples during training. A common strategy is reconstruction: a model is trained to reconstruct normal images, and the difference between a test image and its reconstruction indicates anomalies. However, traditional Autoencoders (AEs) often produce blurry results or fail by reconstructing the anomalies themselves. Generative Adversarial Networks (GANs) offer sharper images but suffer from training instability. While Diffusion Models (DMs) have shown promise in high-quality generation, their application to UAD often lacks a rigorous mathematical foundation for local repair, frequently destroying global texture during the noise-addition process.

The MDPS Framework

MDPS addresses these challenges by treating the test image as a masked noisy observation of a latent normal image. The core of the method is a Bayesian framework that samples from the posterior distribution $p(x_0|y)$, where $x_0$ is the clean normal image and $y$ is the observed test image.

Masked Observation Model

Unlike standard diffusion methods that add noise to the entire image, MDPS employs a mask to protect regions likely to be normal. This ensures that the "repaired" image maintains the original high-quality texture in non-anomalous areas, preventing the global blurring common in other approaches.

Posterior Sampling with DDIM

The framework utilizes a Denoising Diffusion Implicit Model (DDIM) as a prior. During the reverse diffusion process, a guidance scale $\rho$ modulates the influence of the observation $y$. This guidance helps the model decide the extent of "correction" required. The final anomaly score is computed by comparing the original image with an average of multiple posterior samples using a combination of $L_1$ and perceptual (LPIPS) metrics.

The MDPS pipeline: Noisy versions of a test image are processed through a specialized denoiser to generate multiple "normal" samples, which are then averaged to create the final anomaly map.

Experimental Evaluation

The MDPS model was rigorously tested on two primary industrial benchmarks: MVTec AD and BTAD.

Quantitative Results

MDPS establishes a new state-of-the-art for reconstruction-based UAD. On the MVTec AD dataset, it achieved an Image-AUROC of 98.8% and a Pixel-AUROC of 97.3%, significantly outperforming previous diffusion-based baselines like RAN and AutoDDPM. Similar high performance was observed on the BTAD dataset, with 98.4% Image-AUROC and 97.7% Pixel-AUROC.

Qualitative Comparison

Visual analysis confirms that MDPS produces significantly sharper and more accurate "normal" reconstructions than competing methods. While models like DRÆM often produce blurry outputs that can mask defects or create false positives, MDPS maintains crisp textures, leading to clearer and more precise anomaly maps.

Qualitative comparison showing that MDPS provides sharper, more accurate reconstructions than other methods, leading to clearer anomaly maps.

Discussion and Conclusion

The success of MDPS stems from its ability to balance reconstruction fidelity with anomaly removal. The guidance scale $\rho$ acts as a critical hyperparameter; the authors identified $\rho=100$ as optimal for balancing reconstruction quality. Furthermore, the use of multiple posterior samples ($N_s=16$) provides a "wisdom of the crowd" effect, filtering out stochastic noise in the diffusion process.

Despite its performance, MDPS is computationally more intensive than simple Autoencoders due to the iterative nature of diffusion sampling. Future research may focus on knowledge distillation to transfer the high-quality reconstruction capabilities of MDPS into faster, real-time architectures suitable for high-speed industrial applications.

Summary updated

BibTeX
@inproceedings{wu2024unsupervised,
  author = {Di Wu and Shicai Fan and Xue Zhou and Yu Li and Yuzhong Deng and Jianxiao Zou and Baihong Lin and Yingzong Liu and Jianhui Mei and Maolei Fu and Yun Ye and Zhujin Liang and Yi Shan and Dalong Du},
  title = {{Unsupervised Anomaly Detection via Masked Diffusion Posterior Sampling}},
  booktitle = {International Joint Conference on Artificial Intelligence},
  year = {2024},
}
Figure