Unofficial PyTorch implementation of MetaUAS: Universal Anomaly Segmentation with One-Prompt Meta-Learning.
Install LaMa and download the pretrained model:
git clone https://github.com/advimman/lama.git
pip install -r lama/requirements.txt
curl -LJO https://huggingface.co/smartywu/big-lama/resolve/main/big-lama.zip
unzip big-lama.zip -d lama/big-lama/Then prepare COCO train2017 images and annotations:
# Expected structure:
# /path/to/datasets/images/train2017/ # COCO train images
# /path/to/datasets/images/annotations/ # instances_train2017.json
# Generate CYWS coco-inpainted dataset
bash scripts/run_generate_cyws_dataset.shAdjust paths in
scripts/run_generate_cyws_dataset.shbefore running.Alternatively, you can directly download the pre-generated COCO inpainted dataset from CYWS.
pip install -r requirements.txt
bash scripts/train_on_4gpu.shTwo evaluation modes are supported:
- Oneprompt: one random normal sample per class as prompt, multi-seed averaging
- TopK: per-image top-k most similar normal samples as prompts
# Download pretrained checkpoint
wget https://huggingface.co/ldl010302/MetaUAS/resolve/main/metauas-256.pth
# Run both modes on MVTec AD and VisA
bash scripts/run_eval_mvtec.shAdjust
CKPT,MVTEC_ROOT,VISA_ROOTinscripts/run_eval_mvtec.shbefore running.
Experiments run on 4× NVIDIA RTX 3090, batch size 96/GPU, lr=1e-4, weight decay=0.005.
| Methods | Categories | Anomaly Classification | Anomaly Segmentation | |||||
|---|---|---|---|---|---|---|---|---|
| I-ROC | I-PR | I-F1max | P-ROC | P-PR | P-F1max | P-PRO | ||
| MetaUAS | bottle | 98.9±0.9 | 99.7±0.2 | 98.3±0.9 | 98.3±0.7 | 84.4±2.0 | 75.9±1.2 | 93.6±1.4 |
| cable | 91.1±1.9 | 95.2±0.9 | 86.9±1.4 | 94.3±0.3 | 66.7±1.0 | 63.4±1.2 | 86.7±1.3 | |
| capsule | 69.9±3.7 | 90.6±3.5 | 92.1±1.4 | 93.8±0.6 | 28.4±8.9 | 34.5±5.5 | 62.4±2.7 | |
| carpet | 99.6±0.2 | 99.9±0.0 | 99.0±0.4 | 98.1±0.2 | 68.8±1.0 | 64.3±0.5 | 96.0±0.6 | |
| grid | 91.7±1.2 | 97.3±0.4 | 90.2±1.3 | 93.0±1.7 | 26.8±3.6 | 33.4±3.2 | 74.7±5.8 | |
| hazelnut | 78.8±11.9 | 84.8±11.2 | 84.5±2.6 | 96.0±1.3 | 34.0±13.1 | 39.7±9.7 | 80.6±5.8 | |
| leather | 100.0±0.0 | 100.0±0.0 | 100.0±0.0 | 99.4±0.1 | 61.3±1.9 | 56.4±1.4 | 99.0±0.1 | |
| metal nut | 95.5±2.0 | 98.9±0.5 | 95.4±1.4 | 96.4±0.7 | 80.4±3.7 | 73.7±2.8 | 90.5±2.2 | |
| pill | 90.2±2.8 | 98.1±0.6 | 93.2±0.9 | 95.6±0.9 | 64.3±5.2 | 59.8±3.5 | 92.5±0.7 | |
| screw | 53.6±5.2 | 76.7±3.5 | 85.5±0.4 | 92.0±1.6 | 4.6±1.2 | 9.6±2.1 | 71.2±4.4 | |
| tile | 96.0±1.3 | 98.7±0.4 | 94.6±1.6 | 94.0±1.4 | 75.8±1.9 | 69.6±1.3 | 87.0±2.7 | |
| toothbrush | 92.8±1.6 | 97.4±0.6 | 92.0±1.7 | 98.4±0.3 | 58.8±2.4 | 59.6±2.9 | 83.8±1.2 | |
| transistor | 83.9±5.4 | 82.4±4.6 | 74.6±5.9 | 85.7±3.4 | 40.6±5.3 | 40.7±5.4 | 75.2±5.2 | |
| wood | 99.8±0.2 | 99.9±0.1 | 99.2±0.0 | 94.1±0.7 | 68.7±1.6 | 64.7±1.2 | 93.9±0.6 | |
| zipper | 95.0±2.8 | 98.5±0.9 | 95.3±2.0 | 97.1±1.1 | 58.9±4.5 | 55.7±3.1 | 69.7±5.2 | |
| mean | 89.1±1.1 | 94.5±1.0 | 92.1±0.6 | 95.1±0.2 | 54.8±0.9 | 53.4±0.6 | 83.8±0.6 | |
| Methods | Categories | Anomaly Classification | Anomaly Segmentation | |||||
|---|---|---|---|---|---|---|---|---|
| I-ROC | I-PR | I-F1max | P-ROC | P-PR | P-F1max | P-PRO | ||
| MetaUAS* | bottle | 99.5 | 99.9 | 98.4 | 98.4 | 83.9 | 75.2 | 92.9 |
| cable | 96.3 | 98.0 | 93.4 | 96.4 | 70.5 | 66.1 | 91.2 | |
| capsule | 89.3 | 97.5 | 93.7 | 95.4 | 45.7 | 46.4 | 68.5 | |
| carpet | 99.7 | 99.9 | 98.9 | 97.9 | 68.2 | 64.0 | 95.4 | |
| grid | 95.7 | 98.7 | 93.7 | 94.0 | 29.4 | 36.8 | 79.7 | |
| hazelnut | 99.6 | 99.8 | 97.9 | 98.8 | 68.2 | 66.9 | 92.8 | |
| leather | 100.0 | 100.0 | 100.0 | 99.4 | 61.1 | 57.0 | 98.8 | |
| metal nut | 97.2 | 99.4 | 96.3 | 97.2 | 83.1 | 76.6 | 93.6 | |
| pill | 82.5 | 96.7 | 91.6 | 94.0 | 58.6 | 57.4 | 91.0 | |
| screw | 82.4 | 92.7 | 87.0 | 97.4 | 23.6 | 27.9 | 65.4 | |
| tile | 96.6 | 98.9 | 94.4 | 94.7 | 76.7 | 71.1 | 88.7 | |
| toothbrush | 96.4 | 98.6 | 93.8 | 99.0 | 64.3 | 63.2 | 81.2 | |
| transistor | 89.0 | 86.3 | 79.1 | 87.9 | 45.2 | 45.0 | 79.3 | |
| wood | 99.7 | 99.9 | 98.4 | 93.2 | 67.0 | 63.0 | 93.7 | |
| zipper | 93.6 | 98.1 | 95.0 | 96.8 | 58.4 | 56.2 | 68.2 | |
| mean | 94.5 | 97.6 | 94.1 | 96.0 | 60.2 | 58.2 | 85.4 | |
| Methods | Categories | Anomaly Classification | Anomaly Segmentation | |||||
|---|---|---|---|---|---|---|---|---|
| I-ROC | I-PR | I-F1max | P-ROC | P-PR | P-F1max | P-PRO | ||
| MetaUAS | candle | 90.1±1.2 | 90.6±1.0 | 84.0±1.9 | 98.4±0.4 | 33.1±2.5 | 38.8±1.3 | 85.5±1.8 |
| capsules | 62.7±5.5 | 73.4±4.0 | 78.1±0.6 | 92.2±2.2 | 16.0±2.8 | 24.7±1.9 | 52.2±2.3 | |
| cashew | 86.1±2.8 | 93.7±1.3 | 85.6±2.1 | 97.2±1.3 | 71.7±3.3 | 67.9±2.6 | 79.2±2.0 | |
| chewinggum | 96.9±1.0 | 98.7±0.4 | 94.5±0.6 | 99.5±0.1 | 82.5±1.2 | 76.6±0.8 | 85.3±0.9 | |
| fryum | 78.9±2.7 | 89.2±2.9 | 82.0±0.9 | 86.6±1.7 | 19.9±3.5 | 29.0±2.9 | 48.2±5.8 | |
| macaroni1 | 77.2±1.4 | 80.7±0.8 | 71.9±1.7 | 92.6±2.4 | 12.7±0.7 | 21.6±0.6 | 56.9±4.2 | |
| macaroni2 | 58.9±7.3 | 56.9±6.8 | 68.8±1.7 | 90.1±1.7 | 0.9±0.5 | 3.9±1.9 | 65.0±7.2 | |
| pcb1 | 64.9±21.6 | 70.3±13.2 | 75.2±9.1 | 98.1±0.5 | 63.1±4.1 | 60.5±4.0 | 68.8±13.2 | |
| pcb2 | 69.1±3.1 | 67.8±2.0 | 69.6±2.3 | 96.2±0.8 | 14.8±2.5 | 25.8±3.8 | 75.7±3.3 | |
| pcb3 | 62.4±6.7 | 63.7±8.0 | 69.0±1.4 | 96.8±0.3 | 26.1±3.6 | 31.2±3.3 | 61.9±5.2 | |
| pcb4 | 95.5±1.4 | 95.3±1.2 | 90.2±2.1 | 97.3±1.0 | 34.9±3.8 | 43.0±3.9 | 78.8±2.4 | |
| pipe_fryum | 95.4±1.9 | 97.5±1.1 | 93.6±1.9 | 98.7±0.5 | 67.8±3.3 | 63.2±2.2 | 85.8±1.3 | |
| mean | 78.2±2.0 | 81.5±1.5 | 80.2±1.0 | 95.3±0.5 | 37.0±0.9 | 40.5±0.6 | 70.3±1.5 | |
| Methods | Categories | Anomaly Classification | Anomaly Segmentation | |||||
|---|---|---|---|---|---|---|---|---|
| I-ROC | I-PR | I-F1max | P-ROC | P-PR | P-F1max | P-PRO | ||
| MetaUAS* | candle | 91.2 | 91.2 | 84.7 | 98.6 | 35.2 | 39.1 | 84.9 |
| capsules | 62.9 | 77.3 | 76.9 | 94.5 | 30.7 | 35.6 | 58.1 | |
| cashew | 85.5 | 93.4 | 84.3 | 98.6 | 77.9 | 71.4 | 76.8 | |
| chewinggum | 97.3 | 98.8 | 93.7 | 99.5 | 82.2 | 76.4 | 86.6 | |
| fryum | 79.5 | 89.9 | 81.7 | 88.9 | 22.3 | 31.7 | 37.7 | |
| macaroni1 | 75.7 | 77.5 | 72.0 | 93.6 | 11.6 | 20.0 | 49.5 | |
| macaroni2 | 59.2 | 56.3 | 68.1 | 91.7 | 1.1 | 5.6 | 67.8 | |
| pcb1 | 82.5 | 80.5 | 77.1 | 99.2 | 76.3 | 71.3 | 69.3 | |
| pcb2 | 70.0 | 69.6 | 67.7 | 97.2 | 14.8 | 26.3 | 79.0 | |
| pcb3 | 76.2 | 75.8 | 73.6 | 97.2 | 31.1 | 35.5 | 57.0 | |
| pcb4 | 95.3 | 95.6 | 88.5 | 96.8 | 35.6 | 43.8 | 72.2 | |
| pipe_fryum | 95.7 | 97.7 | 94.2 | 98.4 | 64.1 | 60.2 | 88.6 | |
| mean | 80.9 | 83.6 | 80.2 | 96.2 | 40.2 | 43.1 | 69.0 | |
MetaUAS: metauas-256.pth
We reference code from MetaUAS, LaMa, and CYWS.
- ⭐ If you find this project useful, a star would be greatly appreciated
- 🐛 Report bugs or ask questions via Issues
- 🔀 Fork and submit a PR with your improvements — we'll review and add you to the contributors
