Anomaly inspection plays an important role in industrial manufacture. Existing anomaly inspection methods are limited in their performance due to insufficient anomaly data. Although anomaly generation methods have been proposed to augment the anomaly data, they either suffer from poor generation authenticity or inaccurate alignment between the generated anomalies and masks. To address the above problems, we propose AnomalyDiffusion, a novel diffusion-based few-shot anomaly generation model, which utilizes the strong prior information of latent diffusion model learned from large-scale dataset to enhance the generation authenticity under few-shot training data. Firstly, we propose Spatial Anomaly Embedding, which consists of a learnable anomaly embedding and a spatial embedding encoded from an anomaly mask, disentangling the anomaly information into anomaly appearance and location information. Moreover, to improve the alignment between the generated anomalies and the anomaly masks, we introduce a novel Adaptive Attention Re-weighting Mechanism. Based on the disparities between the generated anomaly image and normal sample, it dynamically guides the model to focus more on the areas with less noticeable generated anomalies, enabling generation of accurately-matched anomalous image-mask pairs. Extensive experiments demonstrate that our model significantly outperforms the state-of-the-art methods in generation authenticity and diversity, and effectively improves the performance of downstream anomaly inspection tasks. The code and data are available in https://github.com/sjtuplayer/anomalydiffusion.
翻译:异常检测在工业制造中发挥着重要作用。现有异常检测方法因异常数据不足而性能受限。尽管已提出异常生成方法用于增强异常数据,但这些方法要么生成真实性较差,要么生成的异常与掩模之间对齐不准确。为解决上述问题,我们提出AnomalyDiffusion——一种基于扩散的新型少样本异常生成模型,该模型利用潜在扩散模型从大规模数据集中习得的强先验信息,在少量训练数据下提升生成真实性。首先,我们提出空间异常嵌入,它由可学习的异常嵌入和从异常掩模编码的空间嵌入组成,将异常信息解耦为异常外观与位置信息。此外,为改善生成异常与异常掩模的对齐效果,我们引入一种新型自适应注意力重加权机制。该机制基于生成异常图像与正常样本之间的差异,动态引导模型聚焦于异常生成不够明显的区域,从而生成精确匹配的异常图像-掩模对。大量实验表明,我们的模型在生成真实性和多样性方面显著优于现有方法,并有效提升了下游异常检测任务的性能。代码与数据详见https://github.com/sjtuplayer/anomalydiffusion。