MAGIC: Few-Shot Mask-Guided Anomaly Inpainting with Prompt Perturbation, Spatially Adaptive Guidance, and Context Awareness
About
Few-shot anomaly generation is a key challenge in industrial quality control. Although diffusion models are promising, existing methods struggle: global prompt-guided approaches corrupt normal regions, and existing inpainting-based methods often lack the in-distribution diversity essential for robust downstream models. We propose MAGIC, a fine-tuned inpainting framework that generates high-fidelity anomalies that strictly adhere to the mask while maximizing this diversity. MAGIC introduces three complementary components: (i) Gaussian prompt perturbation, which prevents model overfitting in the few-shot setting by learning and sampling from a smooth manifold of realistic anomalies, (ii) spatially adaptive guidance that applies distinct guidance strengths to the anomaly and background regions, and (iii) context-aware mask alignment to relocate masks for plausible placement within the host object. Under consistent identical evaluation protocol, MAGIC outperforms state-of-the-art methods on diverse anomaly datasets in downstream tasks
Related benchmarks
| Task | Dataset | Result | Rank | |
|---|---|---|---|---|
| Anomaly Localization | MVTec-AD (test) | Pixel AUROC99.8 | 211 | |
| Anomaly Generation | MVTec AD | KID40.27 | 85 | |
| Image-level Anomaly Detection | MVTec AD | AUROC99.36 | 82 | |
| Image-level Anomaly Detection | VisA | AUC94.28 | 80 | |
| Anomaly Generation | VisA | IC-LPIPS32 | 62 | |
| Anomaly Classification | MVTec-AD (test) | -- | 50 | |
| Anomaly Localization | VisA | -- | 35 | |
| Image-level Anomaly Detection | DAGM | AUROC99.86 | 33 | |
| Anomaly Generation | MVTec-AD (test) | IC-LPIPS0.13 | 33 | |
| Anomaly Localization | MVTec 3D-AD | -- | 29 |