Xuhai Chen, Jiangning Zhang, Guanzhong Tian, Haoyang He, Wuhao Zhang, Yabiao Wang, Chengjie Wang, Yong Liu
This repository contains the official PyTorch implementation of the paper CLIP-AD. It is an upgraded version of the method we proposed for the competition.
-
Prepare experimental environments
pip install -r requirements.txt
- Download and extract MVTec-AD into
data/mvtec
- run
python data/mvtec.py
to obtaindata/mvtec/meta.json
data
├── mvtec
├── meta.json
├── bottle
├── train
├── good
├── 000.png
├── test
├── good
├── 000.png
├── anomaly1
├── 000.png
├── ground_truth
├── anomaly1
├── 000.png
- Download and extract VisA into
data/visa
- run
python data/visa.py
to obtaindata/visa/meta.json
data
├── visa
├── meta.json
├── candle
├── Data
├── Images
├── Anomaly
├── 000.JPG
├── Normal
├── 0000.JPG
├── Masks
├── Anomaly
├── 000.png
- Download and extract ISIC into
data/isic
data
├── isic
├── ISBI2016_ISIC_Part1_Test_Data
├── ISIC_0000003.jpg
├── ISBI2016_ISIC_Part1_Test_GroundTruth
├── ISIC_0000003_Segmentation.png
- Download and extract CVC-ClinicDB into
data/cvc_clinicdb
data
├── cvc_clinicdb
├── Ground Truth
├── 1.tif
├── Original
├── 1.tif
├── README.txt
- Download and extract HeadCT into
data/headct
data
├── headct
├── head_ct
├── head_ct
├── 000.png
├── labels.csv
- Download and extract BrainMRI into
data/brainmri
data
├── brainmri
├── brain_tumor_dataset
├── no
├── 1 no.jpeg
├── yes
├── Y1.jpg
├── no
├── 1 no.jpeg
├── yes
├── Y1.jpg
Set parameters in test_SDP.sh
.
dataset
: name of the testing dataset, optional: mvtec, visadata_path
: the path to the testing datasetmodel
: the CLIP modelpretrained
: the pretrained weightsfeatures_list
: features of different layers to useimage_size
: the size of the input imagesrep_vec
: the method for selecting representative vectors, optional: mean, pca, kde, dbscan, mean_shift
Then run the following command
test_SDP.sh
Set parameters in train_SDP_plus.sh
.
print_freq
: the frequency of printing logssave_freq
: the frequency of conducting validation and saving the modelepochs
: total epochs
Then run the following command
train_SDP_plus.sh
The pretrained models are in ./pretrained_models
.
Set parameters in test_SDP_plus.sh
.
checkpoint
: the path to the checkpoint
Then run the following command
test_SDP_plus.sh
If our work is helpful for your research, please consider citing:
@article{chen2023clip,
title={Clip-ad: A language-guided staged dual-path model for zero-shot anomaly detection},
author={Chen, Xuhai and Zhang, Jiangning and Tian, Guanzhong and He, Haoyang and Zhang, Wuhao and Wang, Yabiao and Wang, Chengjie and Wu, Yunsheng and Liu, Yong},
journal={arXiv preprint arXiv:2311.00453},
year={2023}
}