Skip to content

DeLunnLi/MetaUAS

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MetaUAS

Unofficial PyTorch implementation of MetaUAS: Universal Anomaly Segmentation with One-Prompt Meta-Learning.

🖼️ Framework

MetaUAS Framework

🚀 Usage

1. 🔧 COCO Data Preprocessing

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.sh

Adjust paths in scripts/run_generate_cyws_dataset.sh before running.

Alternatively, you can directly download the pre-generated COCO inpainted dataset from CYWS.

2. 🔥 Training

pip install -r requirements.txt
bash scripts/train_on_4gpu.sh

3. 📈 Evaluation

Two 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.sh

Adjust CKPT, MVTEC_ROOT, VISA_ROOT in scripts/run_eval_mvtec.sh before running.

📊 Performance & Checkpoints

Experiments run on 4× NVIDIA RTX 3090, batch size 96/GPU, lr=1e-4, weight decay=0.005.

Results

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.999.7±0.298.3±0.998.3±0.784.4±2.075.9±1.293.6±1.4
cable91.1±1.995.2±0.986.9±1.494.3±0.366.7±1.063.4±1.286.7±1.3
capsule69.9±3.790.6±3.592.1±1.493.8±0.628.4±8.934.5±5.562.4±2.7
carpet99.6±0.299.9±0.099.0±0.498.1±0.268.8±1.064.3±0.596.0±0.6
grid91.7±1.297.3±0.490.2±1.393.0±1.726.8±3.633.4±3.274.7±5.8
hazelnut78.8±11.984.8±11.284.5±2.696.0±1.334.0±13.139.7±9.780.6±5.8
leather100.0±0.0100.0±0.0100.0±0.099.4±0.161.3±1.956.4±1.499.0±0.1
metal nut95.5±2.098.9±0.595.4±1.496.4±0.780.4±3.773.7±2.890.5±2.2
pill90.2±2.898.1±0.693.2±0.995.6±0.964.3±5.259.8±3.592.5±0.7
screw53.6±5.276.7±3.585.5±0.492.0±1.64.6±1.29.6±2.171.2±4.4
tile96.0±1.398.7±0.494.6±1.694.0±1.475.8±1.969.6±1.387.0±2.7
toothbrush92.8±1.697.4±0.692.0±1.798.4±0.358.8±2.459.6±2.983.8±1.2
transistor83.9±5.482.4±4.674.6±5.985.7±3.440.6±5.340.7±5.475.2±5.2
wood99.8±0.299.9±0.199.2±0.094.1±0.768.7±1.664.7±1.293.9±0.6
zipper95.0±2.898.5±0.995.3±2.097.1±1.158.9±4.555.7±3.169.7±5.2
mean 89.1±1.194.5±1.092.1±0.695.1±0.254.8±0.953.4±0.683.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.599.998.498.483.975.292.9
cable96.398.093.496.470.566.191.2
capsule89.397.593.795.445.746.468.5
carpet99.799.998.997.968.264.095.4
grid95.798.793.794.029.436.879.7
hazelnut99.699.897.998.868.266.992.8
leather100.0100.0100.099.461.157.098.8
metal nut97.299.496.397.283.176.693.6
pill82.596.791.694.058.657.491.0
screw82.492.787.097.423.627.965.4
tile96.698.994.494.776.771.188.7
toothbrush96.498.693.899.064.363.281.2
transistor89.086.379.187.945.245.079.3
wood99.799.998.493.267.063.093.7
zipper93.698.195.096.858.456.268.2
mean 94.597.694.196.060.258.285.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.290.6±1.084.0±1.998.4±0.433.1±2.538.8±1.385.5±1.8
capsules62.7±5.573.4±4.078.1±0.692.2±2.216.0±2.824.7±1.952.2±2.3
cashew86.1±2.893.7±1.385.6±2.197.2±1.371.7±3.367.9±2.679.2±2.0
chewinggum96.9±1.098.7±0.494.5±0.699.5±0.182.5±1.276.6±0.885.3±0.9
fryum78.9±2.789.2±2.982.0±0.986.6±1.719.9±3.529.0±2.948.2±5.8
macaroni177.2±1.480.7±0.871.9±1.792.6±2.412.7±0.721.6±0.656.9±4.2
macaroni258.9±7.356.9±6.868.8±1.790.1±1.70.9±0.53.9±1.965.0±7.2
pcb164.9±21.670.3±13.275.2±9.198.1±0.563.1±4.160.5±4.068.8±13.2
pcb269.1±3.167.8±2.069.6±2.396.2±0.814.8±2.525.8±3.875.7±3.3
pcb362.4±6.763.7±8.069.0±1.496.8±0.326.1±3.631.2±3.361.9±5.2
pcb495.5±1.495.3±1.290.2±2.197.3±1.034.9±3.843.0±3.978.8±2.4
pipe_fryum95.4±1.997.5±1.193.6±1.998.7±0.567.8±3.363.2±2.285.8±1.3
mean 78.2±2.081.5±1.580.2±1.095.3±0.537.0±0.940.5±0.670.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.291.284.798.635.239.184.9
capsules62.977.376.994.530.735.658.1
cashew85.593.484.398.677.971.476.8
chewinggum97.398.893.799.582.276.486.6
fryum79.589.981.788.922.331.737.7
macaroni175.777.572.093.611.620.049.5
macaroni259.256.368.191.71.15.667.8
pcb182.580.577.199.276.371.369.3
pcb270.069.667.797.214.826.379.0
pcb376.275.873.697.231.135.557.0
pcb495.395.688.596.835.643.872.2
pipe_fryum95.797.794.298.464.160.288.6
mean 80.983.680.296.240.243.169.0

Pretrained Models

MetaUAS: metauas-256.pth

🙏 Acknowledgements

We reference code from MetaUAS, LaMa, and CYWS.

🤝 Contributing

  • ⭐ 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

About

Unofficial PyTorch implementation of MetaUAS (NeurIPS 2024).

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors