Code Monkey home page Code Monkey logo

promptad's Introduction

PromptAD Few-Shot Anomaly Detection

Official implementation of PromptAD: Learning Prompts with only Normal Samples for Few-Shot Anomaly Detection (CVPR2024)

RUNOOB 图标

Install

conda create -n prompt_ad python==3.10
conda activate prompt_ad
bash install.sh

Data

Download the dataset from MvTec.

Download the dataset from VisA.

VisA preprocessing

Modify the source and target paths for the VisA dataset in ./dataset/prepare_visa_public.py

python ./dataset/prepare_visa_public.py

Modify the source paths for MvTec and VisA in ./dataset/mvtec.py and ./dataset/visa.py

Run

python run_cls.py  # image-level
python run_seg.py  # pixel-level

Citation

Please cite the following paper if this work helps your project:

@article{li2024promptad,
  title={PromptAD: Learning Prompts with only Normal Samples for Few-Shot Anomaly Detection},
  author={Li, Xiaofan and Zhang, Zhizhong and Tan, Xin and Chen, Chengwei and Qu, Yanyun and Xie, Yuan and Ma, Lizhuang},
  journal={arXiv preprint arXiv:2404.05231},
  year={2024}
}

Acknowledge

We thank the great works WinCLIP and CoOp for assisting with our work.

promptad's People

Contributors

funz-0 avatar

Stargazers

coordxyz avatar  avatar  avatar phurich avatar Jiaxiong Yang avatar  avatar Kim Yongmin avatar  avatar zorro avatar JongHan Leem avatar Yanwei Liu avatar Hui_Official avatar GreatLuis avatar Wu Jingyu avatar Jin  Huang avatar Michael Kösel avatar evan cai avatar  avatar Jisu Kang avatar Howeng avatar Feng Duoduo avatar  avatar Fahad Shamshad avatar TOMCAT avatar Lawrence avatar  avatar  avatar killer9 avatar WangFengJie avatar  avatar GSong avatar Howard H. Tang avatar  avatar 高亮 avatar  avatar Xiaopeng Wang avatar Mengyang Zhao avatar  avatar WateRice avatar xiaolin avatar dyy avatar Xiankai Chen avatar Aaron Tang avatar 이재혁 avatar saidinesh pola avatar ivan avatar liwenyang-911 avatar Airlamb avatar Jingsong Xu avatar jwmneu avatar  avatar  avatar Donghyeong Kim avatar  avatar Xurui Li avatar 陶光品 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar HJ Im avatar HcSoap avatar  avatar  avatar WU Sik Chit / 胡释哲 avatar  avatar  avatar

Watchers

Howard H. Tang avatar  avatar

Forkers

yoojlee yqlzbqc

promptad's Issues

Screw class seems fail to reach the reported detetcion AUROC

There is no denying that promptAD is a very impressive work and thanks for the open resoursing for the knowledge broadcast in the field of AD.
But for those who is familiar with the mvtec dataset, there is no dout that the screw class is the most challenging one because of the none-allignment(basicly the rotation). In your paper , you report that in one-shot the auroc is blow 70,and then in two-shot setting the metric reach 98,and in four shot the metric just rocket to 100? Bro, u got be kidding me, since u even miswrite the carpet class with Garpet in your supplymentary table. I don't want to be mean, but you know, the data i see is just unrealist to me. And I run your code, and in each shot ,the detection auroc of screw is around 70.
And I think maybe the blame is not on you, so I check your baseline code the repo(WinClip) that be reimplemented by Mr.caoyunkang. In Cao's reimplentation, WinCLIP cannaot reach the reported detection auroc of amazon reported in class screw too,with a large margin of 20. Which makes me concused aboat which data should i really quote, the ones written in the paper, or the one i saw with my own eyes.

run_seg.py shots有什么含义?

从代码看就是单纯的控制循环次数,每个类别在不同的循环里跑出来的结果都是一样的,所以设计成[1,2,4]有什么特殊含义吗?它并没有按照论文所说的那样起作用
1-shot
Object:carpet =========================== Pixel-AUROC:99.53
Object:grid =========================== Pixel-AUROC:98.14
Object:leather =========================== Pixel-AUROC:99.39
Object:tile =========================== Pixel-AUROC:96.05
Object:wood =========================== Pixel-AUROC:95.82
Object:bottle =========================== Pixel-AUROC:97.31
Object:cable =========================== Pixel-AUROC:94.3
Object:capsule =========================== Pixel-AUROC:95.35
Object:hazelnut =========================== Pixel-AUROC:98.28
Object:metal_nut =========================== Pixel-AUROC:91.6
Object:pill =========================== Pixel-AUROC:93.61
Object:screw =========================== Pixel-AUROC:93.63
Object:toothbrush =========================== Pixel-AUROC:98.71
Object:transistor =========================== Pixel-AUROC:85.68
Object:zipper =========================== Pixel-AUROC:94.05

2-shot
Object:carpet =========================== Pixel-AUROC:99.53
Object:grid =========================== Pixel-AUROC:98.14
Object:leather =========================== Pixel-AUROC:99.39
Object:tile =========================== Pixel-AUROC:96.05
Object:wood =========================== Pixel-AUROC:95.82
Object:bottle =========================== Pixel-AUROC:97.31
Object:cable =========================== Pixel-AUROC:94.3
Object:capsule =========================== Pixel-AUROC:95.35
Object:hazelnut =========================== Pixel-AUROC:98.28
Object:metal_nut =========================== Pixel-AUROC:91.6
Object:pill =========================== Pixel-AUROC:93.61
Object:screw =========================== Pixel-AUROC:93.63
Object:toothbrush =========================== Pixel-AUROC:98.71
Object:transistor =========================== Pixel-AUROC:85.68
Object:zipper =========================== Pixel-AUROC:94.05

4-shot
Object:carpet =========================== Pixel-AUROC:99.53
Object:grid =========================== Pixel-AUROC:98.14
Object:leather =========================== Pixel-AUROC:99.39
Object:tile =========================== Pixel-AUROC:96.05
Object:wood =========================== Pixel-AUROC:95.82
Object:bottle =========================== Pixel-AUROC:97.31
Object:cable =========================== Pixel-AUROC:94.3
Object:capsule =========================== Pixel-AUROC:95.35
Object:hazelnut =========================== Pixel-AUROC:98.28
Object:metal_nut =========================== Pixel-AUROC:91.6
Object:pill =========================== Pixel-AUROC:93.61
Object:screw =========================== Pixel-AUROC:93.63
Object:toothbrush =========================== Pixel-AUROC:98.71
Object:transistor =========================== Pixel-AUROC:85.68
Object:zipper =========================== Pixel-AUROC:94.05

另外,以默认参数运行run_seg.py,得到的pixel-level的AUROC达不到论文精度,相差较远,是否有什么特别的设定需要更改

Code

Dear authors, thank you for your excellent work, and when will the code be released?

test on one new image

Thank you for your great work!
I'm very interested in trying to test this model on some new "industrial" images but I'm wondering how we can test the model on one (or more) new image?

code

Dear authors, thank you for your excellent work, and when will the code be released?

Pre-trained Weights.

Your work is awesome. Do you have pre-trained weights that can be used to reproduce the reported result on paper?

experiments requirements

What hardware configuration is needed to run your work? How much memory is needed for the graphics card? Thank you

Can not reproduce the results

Hi, thanks for your research effort!

Actually, there is no way i can reproduce the results by really far margin. Can you please put the selected hyperparameters that are used for reporting results?

Thanks
Regards.

Execution error with run_cls.py

I executed the run_cls.py file according to the readme and encountered the following error (my env: win10 with rtx3060):
Traceback (most recent call last): File "C:\Users\35314\Desktop\PromptAD\PromptAD\CLIPAD\model.py", line 236, in encode_text_embeddings x = x + self.positional_embedding.to(cast_dtype) RuntimeError: The size of tensor a (105) must match the size of tensor b (77) at non-singleton dimension 1

可能是显卡不支持?

script run_cls.py has error

Hi,
Thanks for sharing your code.
I get an issue when I run the run_cls.py script. Here is the error:

  File "/home/alexandre/projects/PromptAD/train_cls.py", line 257, in <module>
    main(args)
  File "/home/alexandre/projects/PromptAD/train_cls.py", line 189, in main
    metrics = fit(model, args, test_dataloader, device, check_path=check_path, train_data=train_dataloader)
  File "/home/alexandre/projects/PromptAD/train_cls.py", line 76, in fit
    abnormal_text_features_learned = model.encode_text_embedding(abnormal_text_prompt_learned, model.tokenized_abnormal_prompts_learned)
  File "/home/alexandre/projects/PromptAD/PromptAD/model.py", line 252, in encode_text_embedding
    text_features = self.model.encode_text_embeddings(text_embedding, original_tokens)
  File "/home/alexandre/projects/PromptAD/PromptAD/CLIPAD/model.py", line 236, in encode_text_embeddings
    x = x + self.positional_embedding.to(cast_dtype)
RuntimeError: The size of tensor a (105) must match the size of tensor b (77) at non-singleton dimension 1

I followed the procedure that is proposed in the readme.
How can I solve the problem ?
thanks in advance

ps: run_seg.py seems working like a charm

模型能否导出来onnx格式?

我尝试在 test_seg.py中断点,将模型导出为onnx,发现有以下报错:

torch.onnx.export(model, data, "test.onnx") // 这是我临时的导出代码,以下为执行结果消息
Traceback (most recent call last):
File "", line 1, in
File "f:\pyenv\Torch118gpu\lib\site-packages\torch\onnx\utils.py", line 516, in export
_export(
File "f:\pyenv\Torch118gpu\lib\site-packages\torch\onnx\utils.py", line 1612, in _export
graph, params_dict, torch_out = _model_to_graph(
File "f:\pyenv\Torch118gpu\lib\site-packages\torch\onnx\utils.py", line 1134, in _model_to_graph
graph, params, torch_out, module = _create_jit_graph(model, args)
File "f:\pyenv\Torch118gpu\lib\site-packages\torch\onnx\utils.py", line 1010, in _create_jit_graph
graph, torch_out = _trace_and_get_graph_from_model(model, args)
File "f:\pyenv\Torch118gpu\lib\site-packages\torch\onnx\utils.py", line 926, in _trace_and_get_graph_from_model
raise RuntimeError(
RuntimeError: state_dict changed after running the tracer; something weird is happening in your model!

请问是什么原因呀? 如何解决呢?

感谢你们的开源和回复

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.