Abstract
Few-shot anomaly generation is emerging as a practical solution for augmenting the scarce anomaly data in industrial quality control settings. An ideal generator would meet three demands at once, namely (i) keep the normal background intact, (ii) inpaint anomalous regions to tightly overlap with the corresponding anomaly masks, and (iii) generate anomalous regions in a semantically valid location, while still producing realistic, diverse appearances from only a handful of real examples. Existing diffusion-based methods usually satisfy at most two of these requirements: global anomaly generators corrupt the background, whereas mask-guided ones often falter when the mask is imprecise or misplaced. We propose MAGIC--Mask-guided inpainting with multi-level perturbations and Context-aware alignment--to resolve all three issues. At its core, MAGIC fine-tunes a Stable Diffusion inpainting backbone that preserves normal regions and ensures strict adherence of the synthesized anomaly to the supplied mask, directly addressing background corruption and misalignment. To offset the diversity loss that fine-tuning can cause, MAGIC adds two complementary perturbation strategies: (i) Gaussian prompt-level perturbation applied during fine-tuning and inference that broadens the global appearance of anomalies while avoiding low-fidelity textual appearances, and (ii) mask-guided spatial noise injection that enriches local texture variations. Additionally, the context-aware mask alignment module forms semantic correspondences and relocates masks so that every anomaly remains plausibly contained within the host object, eliminating out-of-boundary artifacts. Under a consistent identical evaluation protocol on the MVTec-AD dataset, MAGIC outperforms previous state-of-the-arts in downstream anomaly tasks.
Abstract (translated)
少量样本异常生成正逐渐成为解决工业质量控制环境中稀缺异常数据问题的一种实用解决方案。理想中的生成器需要同时满足以下三个需求:(i)保持正常的背景不变,(ii)在相应的异常掩码上精确绘制异常区域,以及(iii)在语义有效的位置生成异常区域,并且仅从少量的真实样本中就能产生逼真且多样化的外观。 现有的基于扩散的方法通常最多只能满足上述两个要求:全局异常生成器会破坏背景,而掩模引导的生成方法往往在掩模不精确或定位错误时表现不佳。我们提出了一种名为MAGIC(Mask-guided Inpainting with Multi-level Perturbations and Context-aware Alignment)的技术来解决所有这些问题。MAGIC的核心在于对Stable Diffusion修复模型进行微调,以保留正常区域,并确保合成的异常严格遵循提供的掩模,从而直接解决了背景破坏和不对齐的问题。 为了抵消微调可能带来的多样性损失,MAGIC增加了两种互补的扰动策略:(i)在微调和推理过程中应用高斯提示级扰动,这可以扩展全局异常外观的同时避免低质量的文字表现;以及(ii)掩模引导的空间噪声注入,以丰富局部纹理变化。此外,上下文感知的掩模对齐模块建立了语义对应关系并重新定位掩模,确保每个异常都合理地包含在宿主对象内,从而消除了边界外的伪影。 在MVTec-AD数据集上进行一致且相同的评估协议下,MAGIC在下游异常检测任务中超越了之前的最先进方法。
URL
https://arxiv.org/abs/2507.02314