• Stars
    star
    116
  • Rank 302,165 (Top 6 %)
  • Language
    Python
  • Created over 1 year ago
  • Updated 9 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

[CVPR 2023 Workshop] VAND Challenge: 1st Place on Zero-shot AD and 4th Place on Few-shot AD

Workshop Link | Challenge Link | Report Paper

Xuhai Chen Β· Yue Han Β· Jiangning Zhang

This repository contains the official PyTorch implementation of Zero-/Few-shot Anomaly Classification and Segmentation Method used in the CVPR 2023 VAND Challenge, which can be viewd as an improved version of WinCLIP. We achieve Winner in the Zero-shot Track and Honorable Mentions in the Few-shot Track.

Model Structure

Results on the Challenge official test set

Model Structure

Installation

  • Prepare experimental environments

    pip install -r requirements.txt

Dataset Preparation

MVTec AD

  • Download and extract MVTec AD into data/mvtec
  • runpython data/mvtec.py to obtain data/mvtec/meta.json
data
β”œβ”€β”€ mvtec
    β”œβ”€β”€ meta.json
    β”œβ”€β”€ bottle
        β”œβ”€β”€ train
            β”œβ”€β”€ good
                β”œβ”€β”€ 000.png
        β”œβ”€β”€ test
            β”œβ”€β”€ good
                β”œβ”€β”€ 000.png
            β”œβ”€β”€ anomaly1
                β”œβ”€β”€ 000.png
        β”œβ”€β”€ ground_truth
            β”œβ”€β”€ anomaly1
                β”œβ”€β”€ 000.png

VisA

  • Download and extract VisA into data/visa
  • runpython data/visa.py to obtain data/visa/meta.json
data
β”œβ”€β”€ visa
    β”œβ”€β”€ meta.json
    β”œβ”€β”€ candle
        β”œβ”€β”€ Data
            β”œβ”€β”€ Images
                β”œβ”€β”€ Anomaly
                    β”œβ”€β”€ 000.JPG
                β”œβ”€β”€ Normal
                    β”œβ”€β”€ 0000.JPG
            β”œβ”€β”€ Masks
                β”œβ”€β”€ Anomaly
                    β”œβ”€β”€ 000.png

Train

Set parameters in train.sh.

  • train_data_path: the path to the training dataset
  • dataset: name of the training dataset, optional: mvtec, visa
  • model: the CLIP model
  • pretrained: the pretrained weights
  • features_list: features to be mapped into the joint embedding space
  • image_size: the size of the images inputted into the CLIP model
  • aug_rate: the probability of stitching images (only for mvtec)

Then run the following command

sh train.sh

Test

Pretrained Models

We provide our pre-trained models in exps/pretrained, where mvtec_pretrained.pth represents the model trained on the MVTec AD dataset and visa_pretrained.pth represents the model trained on the VisA dataset.

Set parameters in test_zero_shot.sh.

  • data_path: the path to the test dataset
  • dataset: name of the test dataset, optional: mvtec, visa
  • checkpoint_path: the path to the test model

Then, run the following command to test them in the zero-shot setting:

sh test_zero_shot.sh

Set parameters in test_few_shot.sh.

  • data_path: the path to the test dataset
  • dataset: name of the test dataset, optional: mvtec, visa
  • checkpoint_path: the path to the test model
  • k_shot: different number of reference images

Then, run the following command to test them in the few-shot setting:

sh test_few_shot.sh

Zero-shot Setting

Set parameters in test_zero_shot.sh.

  • data_path: the path to the test dataset
  • dataset: name of the test dataset, optional: mvtec, visa
  • checkpoint_path: the path to the test model
  • model: the CLIP model
  • pretrained: the pretrained weights
  • features_list: features to be mapped into the joint embedding space
  • image_size: the size of the images inputted into the CLIP model
  • mode: zero shot or few shot

Then run the following command

sh test_zero_shot.sh

Few-shot Setting

Set parameters in test_few_shot.sh.

  • data_path: the path to the test dataset
  • dataset: name of the test dataset, optional: mvtec, visa
  • checkpoint_path: the path to the test model
  • model: the CLIP model
  • pretrained: the pretrained weights
  • features_list: features to be mapped into the joint embedding space
  • few_shot_features: features stored in the memory banks
  • image_size: the size of the images inputted into the CLIP model
  • mode: zero shot or few shot
  • k_shot: different number of reference images
  • seed: the random seed

Then run the following command

sh test_few_shot.sh

Citation

If our work is helpful for your research, please consider citing:

@article{chen2023zero,
  title={A Zero-/Few-Shot Anomaly Classification and Segmentation Method for CVPR 2023 VAND Workshop Challenge Tracks 1\&2: 1st Place on Zero-shot AD and 4th Place on Few-shot AD},
  author={Chen, Xuhai and Han, Yue and Zhang, Jiangning},
  journal={arXiv preprint arXiv:2305.17382},
  year={2023}
}

Acknowledgements

We thank WinCLIP: Zero-/Few-Shot Anomaly Classification and Segmentation for providing assistance for our research.