Large-Scale Universal Defect Generation: Foundation Models and Datasets
Organizations: Tencent Youtu Lab, Shenzhen, China
Abstract
Existing defect/anomaly generation methods often rely on few-shot learning, which overfits to specific defect categories due to the lack of large-scale paired defect editing data. This issue is aggravated by substantial variations in defect scale and morphology, resulting in limited generalization, degraded realism, and category consistency. We address these challenges by introducing UDG, a large-scale dataset of 300K normal-abnormal-mask-caption quadruplets spanning diverse domains, and by presenting UniDG, a universal defect generation foundation model that supports both reference-based defect generation and text instruction-based defect editing without per-category fine-tuning. UniDG performs Defect-Context Editing via adaptive defect cropping and structured diptych input format, and fuses reference and target conditions through MM-DiT multimodal attention. A two-stage training strategy, Diversity-SFT followed by Consistency-RFT, further improves diversity while enhancing realism and reference consistency. Extensive experiments on MVTec-AD and VisA show that UniDG outperforms prior few-shot anomaly generation and image insertion/editing baselines in synthesis quality and downstream single- and multi-class anomaly detection/localization. Code will be available at https://github.com/RetoFan233/UniDG.
Figures & tables
| Metric | Few-shot Learning Anomaly Generation | Training-Free Few-shot Image Insertion | ||||||
|---|---|---|---|---|---|---|---|---|
| AnoDiff | AnoGen | DualAnoDiff | SeaS | AnyDoor | InsertAny | UniDG-SFT | UniDG-RFT | |
| Cls. | ||||||||
| Acc-C | 68.4 | 61.4 | 64.0 | 59.1 | 61.8 | 63.6 | 74.9 | 77.4 |
| Det.&Loc. | ||||||||
| AUROC-I | 97.9 | 97.0 | 94.9 | 96.2 | 80.3 | 95.3 | 98.0 | 98.4 |
| AP-I | 98.9 | 95.0 | 96.6 | 95.5 | 80.7 | 95.5 | 98.6 | 99.0 |
| Methods | Binary Anomaly Detection Metrics | Semantic Segmentation Metrics | ||||||
|---|---|---|---|---|---|---|---|---|
| AUROC-I | AP-I | AUROC-P | AP-P | PRO-P | mIoU | BG-mIoU | FG-mIoU | |
| Few-shot Anomaly Generation | ||||||||
| AnoDiff | 92.79 | 96.24 | 95.90 | 61.41 | 81.82 +0.0% | 37.87 -4.7% | 98.47 | 23.83 -9.9% |
| AnoGen | 93.10 | 96.20 | 94.85 | 63.32 | 79.54 -2.8% | 39.72 +0.0% | 98.54 | 26.45 +0.0% |
| DualAnoDiff | 91.00 | 95.40 | 95.31 | 63.19 | 79.96 -2.3% | 39.43 -0.7% | 98.57 | 26.27 -0.7% |
| SeaS | 89.29 | 93.76 | 95.89 | 60.98 | 81.01 -1.0% | 35.41 -10.9% | 98.33 | 20.48 -22.6% |
| Arch. | Single-class Metrics | Multi-class Metrics | ||||
|---|---|---|---|---|---|---|
| Acc | AP-I | AP-P | PRO-P | mIoU | FG-mIoU | |
| Baseline | 57.8 | 92.5 | 43.1 | 75.3 | 29.4 | 13.3 |
| + Diptych input | 62.3 | 94.0 | 51.6 | 78.5 | 32.3 | 16.4 |
| + Normal Reg | 64.9 | 94.9 | 56.7 | 82.1 | 34.9 | 22.1 |
| + Defect Attn | 65.5 | 95.8 | 60.1 | 84.0 | 36.1 | 22.8 |
| + Diversity-SFT | 74.9 | 98.6 | 77.0 | 91.0 | 41.8 | 28.5 |
| Data Proportion | Multi-class Metrics | Synthesis Metrics | |||||
|---|---|---|---|---|---|---|---|
| (a) | (b) | (c) | PRO-P | mIoU | FG-mIoU | Cons | Qual |
| 0 | 1 | 1 | 76.2 | 30.3 | 14.5 | 3.82 | 3.73 |
| 1 | 0 | 1 | 78.3 | 31.4 | 15.7 | 3.91 | 3.87 |
| 1 | 1 | 0 | 90.5 | 39.1 | 26.0 | 3.89 | 3.92 |
| 1 | 1 | 1 | 91.0 | 41.8 | 28.5 | 4.15 | 4.09 |
| 2 | 1 | 1 | 90.9 | 41.9 | 28.5 | 4.14 | 4.12 |
Appendix figures & tables18 assets
Supplementary material from the paper’s appendix.
Appendix
| Component | Parameters | Enabled | Status |
|---|---|---|---|
| FLUX.1-Fill-dev | |||
| CLIP Text Encoder | 125M | / | |
| T5 XXL Text Encoder | 4.7B | / | |
| FLUX-VAE | 84M | / | |
| MM-DiT | 12B | / | & LoRA |
| FLUX.1-Redux-dev | |||
| Accuracy | GPT-4.1 | GPT-5 | Gemini-3-Pro | Qwen3-VL | Defect-Und-Reward-4B | Defect-Und-Reward-8B | ||
|---|---|---|---|---|---|---|---|---|
| 4B | 8B | 32B | ||||||
| RefAd | 84.2 | 82.6 | 86.4 | 74.6 | 72.4 | 80.0 | 82.4 | 84.8 |
| Cons | 81.6 | 83.8 | 88.8 | 75.2 | 78.4 | 79.8 | 82.0 | 86.0 |
| Reas | 86.4 | 88.4 | 87.6 | 62.8 | 68.0 | 73.2 | 84.8 | 85.4 |
| Qual | 92.0 | 92.4 | 94.8 | 84.2 | 86.8 | 87.4 | 91.6 | 93.4 |
| Model | Scale | Anomaly | Defect | Object | Average | ||||
|---|---|---|---|---|---|---|---|---|---|
| Discrimination | Classification | Localization | Description | Analysis | Classification | Analysis | |||
| Random Chance | – | 50.00 | 25.00 | 25.00 | 25.00 | 25.00 | 25.00 | 25.00 | 28.57 |
| Human (expert) | – | 95.24 | 75.00 | 92.31 | 83.33 | 94.20 | 86.11 | 80.37 | 86.65 |
| Human (ordinary) | – | 86.90 | 66.25 | 85.58 | 71.25 | 81.52 | 89.58 | 69.72 | 78.69 |
| Claude-3.5-sonnet | – | 60.14 | 60.14 | 48.81 | 67.13 | 79.11 | 85.19 | 79.83 | 68.36 |
| Gemini-1.5-pro | – | 68.63 | 60.12 | 58.56 | 70.38 | 82.46 | 89.20 | 82.25 | 73.09 |
| Method | AnoDiff | AnoGen | DualAnoDiff | SeaS | AnyDoor | InsertAny | UniDG |
|---|---|---|---|---|---|---|---|
| Paradigm | DDIM | Rectified Flow | |||||
| Resolution | |||||||
| Iterations | 50 | 50 | 100 | 25 | 50 | 50 | 28 |
| Inference Time (s) | 3.47 | 3.21 | 19.68 | 6.73 | 7.59 | 28.04 | 11.59 |
| Coefficient | Single-class Metrics | Multi-class Metrics | Synthesis Metrics | ||||||
|---|---|---|---|---|---|---|---|---|---|
| Acc | AP-I | AP-P | PRO-P | mIoU | FG-mIoU | Cons | Qual | ||
| 0.0 | 1.0 | 78.3 | 99.1 | 78.1 | 91.3 | 45.3 | 32.5 | 4.01 | 3.97 |
| 0.2 | 0.8 | 77.6 | 99.0 | 77.6 | 91.2 | 44.7 | 32.2 | 4.15 | 4.17 |
| 0.5 | 0.5 | 77.4 | 99.0 | 77.3 | 91.1 | 44.2 | 31.9 | 4.21 | 4.24 |
| 0.8 | 0.2 | 76.7 | 98.8 | 76.7 | 91.0 | 43.7 | 30.7 | 4.34 | 4.39 |
| 1.0 | 0.0 | 71.6 | 97.3 | 75.8 | 88.3 | 39.8 | 27.1 | 4.59 | 4.67 |
| Method | Metric | Category | Average | ||||||||||||||
| bottle | cable | capsule | carpet | grid | hazelnut | leather | metal_nut | pill | screw | tile | toothbrush | transistor | wood | zipper | |||
| Few-shot Learning Anomaly Generation | |||||||||||||||||
| AnoDiff | AUROC-I | 100.0 | 99.8 | 91.3 | 93.2 | 97.5 | 99.6 | 99.9 | 100.0 | 99.1 | 88.0 | 100.0 | 100.0 | 99.8 | 100.0 | 100.0 | 97.9 |
| AP-I | 100.0 | 99.4 | 97.4 | 95.4 | 99.0 | 99.6 | 100.0 | 100.0 | 98.9 | 93.6 | 100.0 | 100.0 | 99.6 | 100.0 | 100.0 | 98.9 | |
| AUROC-P | 99.1 | 82.2 | 97.7 | 97.2 | 91.8 | 99.7 | 99.8 | 99.6 | 99.8 | 93.6 | 99.1 | 98.1 | 94.1 | 98.3 | 99.4 | 96.6 | |
| AP-P | 87.5 | 82.2 | 34.5 | 78.6 | 30.3 | 95.5 | 77.5 | 98.2 | 96.7 | 37.2 | 92.9 | 60.3 | 94.1 | 78.4 | 87.3 | 75.4 | |
| Category | AnoDiff | AnoGen | DualAnoDiff | SeaS | AnyDoor | InsertAny | UniDG-SFT | UniDG-RFT |
|---|---|---|---|---|---|---|---|---|
| bottle | 90.70 | 53.49 | 55.81 | 83.72 | 65.12 | 79.07 | 88.37 | 83.72 |
| cable | 67.19 | 60.94 | 48.44 | 50.00 | 62.50 | 76.56 | 79.69 | 87.88 |
| capsule | 66.67 | 24.00 | 49.33 | 30.67 | 65.33 | 41.33 | 68.00 | 73.33 |
| carpet | 58.06 | 40.32 | 69.35 | 41.94 | 53.23 | 77.42 | 64.52 | 72.58 |
| grid | 42.50 | 57.50 | 62.50 | 32.50 | 60.00 | 32.50 | 50.00 | 40.00 |
| hazel nut | 85.42 | 85.42 | 79.17 | 85.42 | 81.25 | 95.83 | 95.83 | 95.83 |
| Method | Metric | Category | Average | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| bottle | cable | capsule | carpet | grid | hazelnut | leather | metal_nut | pill | screw | tile | toothbrush | transistor | wood | zipper | |||
| AnoDiff | IL | 0.16 | 0.37 | 0.16 | 0.20 | 0.39 | 0.29 | 0.39 | 0.24 | 0.23 | 0.23 | 0.50 | 0.15 | 0.27 | 0.34 | 0.23 | 0.28 |
| IL-a | 0.17 | 0.13 | 0.08 | 0.14 | 0.11 | 0.17 | 0.10 | 0.22 | 0.14 | 0.07 | 0.21 | 0.14 | 0.16 | 0.18 | 0.12 | 0.14 | |
| RefAd | 3.76 | 4.00 | 3.69 | 3.96 | 4.11 | 3.43 | 3.82 | 3.86 | 3.97 | 3.62 | 3.87 | 2.63 | 3.74 | 3.49 | 4.25 | 3.84 | |
| Cons | 3.80 | 3.93 | 4.13 | 4.29 | 3.62 | 3.54 | 4.21 | 3.92 | 4.16 | 3.75 | 4.13 | 2.99 | 4.01 | 3.82 | 4.00 | 3.97 | |
| Reas | 4.29 | 4.39 | 4.48 | 4.69 | 4.41 | 3.58 | 4.07 | 4.19 | 3.85 | 4.00 | 3.89 | 3.06 | 4.38 | 3.85 | 4.26 | 4.18 | |
| Method | Metric | Category | Average | |||||||||||
| candle | capsules | cashew | chewinggum | fryum | macaroni1 | macaroni2 | pcb1 | pcb2 | pcb3 | pcb4 | pipe_fryum | |||
| Few-shot Learning Anomaly Generation | ||||||||||||||
| SeaS | AUROC-I | 73.70 | 78.20 | 85.90 | 97.00 | 90.40 | 81.30 | 63.80 | 96.80 | 88.00 | 91.50 | 98.10 | 71.30 | 84.67 |
| AP-I | 71.60 | 82.70 | 90.50 | 98.10 | 93.60 | 70.70 | 52.10 | 95.90 | 89.00 | 88.40 | 94.80 | 75.50 | 83.58 | |
| AUROC-P | 84.10 | 98.10 | 98.30 | 98.80 | 96.90 | 98.10 | 91.40 | 97.60 | 94.70 | 90.50 | 95.60 | 99.10 | 95.27 | |
| AP-P | 1.60 | 50.70 | 83.60 | 77.80 | 67.10 | 7.60 | 0.10 | 86.70 | 21.40 | 38.30 | 49.50 | 78.70 | 46.93 | |
| Category | SeaS | UniDG-SFT | UniDG-RFT |
|---|---|---|---|
| candle | 73.70 | 87.50 | 91.20 |
| capsules | 78.20 | 91.20 | 90.40 |
| cashew | 85.90 | 84.30 | 85.20 |
| chewinggum | 97.00 | 96.40 | 96.70 |
| fryum | 90.40 | 92.30 | 91.50 |
| macaroni1 | 81.30 | 89.60 | 92.30 |
| Methods | Binary Anomaly Detection Metrics | Semantic Segmentation Metrics | ||||||
|---|---|---|---|---|---|---|---|---|
| AUROC-I | AP-I | AUROC-P | AP-P | PRO-P | mIoU | BG-mIoU | FG-mIoU | |
| Few-shot Anomaly Generation | ||||||||
| SeaS | 81.72 | 82.87 | 95.83 | 45.85 | 78.73 | 24.99 | 99.58 | 11.83 |
| Training-Free Few-shot Image Insertion | ||||||||
| UniDG-SFT | 89.21 | 91.34 | 97.88 | 58.14 | 88.45 | 31.79 | 99.54 | 18.89 |
| UniDG-RFT | 91.37 | 92.96 | 97.59 | 63.20 | 90.92 | 36.23 | 99.55 | 23.47 |
Synthetic Anomaly Generation
Synthetic anomaly generation creates controlled abnormal examples to train, test, and evaluate detectors when real anomalies are scarce.
See all 65 papers