Git Product home page Git Product logo

bgad's Introduction

PyTorch implementation for CVPR2023 paper, Explicit Boundary Guided Semi-Push-Pull Contrastive Learning for Supervised Anomaly Detection.


Installation

Install all packages with this command:

$ python3 -m pip install -U -r requirements.txt

Download Datasets

Please download MVTecAD dataset from MVTecAD dataset and BTAD dataset from BTAD dataset.

Training

  • Run code for training MVTecAD
python main.py --flow_arch conditional_flow_model --gpu 0 --data_path /path/to/your/dataset --with_fas --data_strategy 0,1 --num_anomalies 10 --not_in_test --exp_name bgad_fas_10 --focal_weighting --pos_beta 0.01 --margin_tau 0.1
  • Run code for training BTAD
python main.py --flow_arch conditional_flow_model --gpu 0 --dataset btad --data_path /path/to/your/dataset --with_fas --data_strategy 0,1 --num_anomalies 10 --not_in_test --exp_name bgad_fas_10 --focal_weighting --pos_beta 0.01 --margin_tau 0.1

Testing

  • Run code for testing
python test.py --flow_arch conditional_flow_model --gpu 0 --checkpoint /path/to/output/dir --phase test --pro 

Citation

If you find this repository useful, please consider citing our work:

@article{BGAD,
      title={Explicit Boundary Guided Semi-Push-Pull Contrastive Learning for Supervised Anomaly Detection}, 
      author={Xincheng Yao and Ruoqi Li and Jing Zhang and Jun Sun and Chongyang Zhang},
      year={2023},
      booktitle={Conference on Computer Vision and Pattern Recognition 2023},
      url={https://arxiv.org/abs/2207.01463},
      primaryClass={cs.CV}
}

Acknowledgement

This repository is built using the timm library, the CFLOW repository and the FrEIA repository.

bgad's People

Contributors

xcyao00 avatar

Stargazers

He Jiabei avatar  avatar Xurui Li avatar Yanwei Liu avatar Road Xu avatar Jingsong Xu avatar Xing Jingyu avatar  avatar  avatar Jure Hudoklin avatar Seeye avatar Valentin BAJENEZA avatar Zhongyang LU avatar  avatar 394481125 avatar EdgarPinto avatar  avatar  avatar André Afonso avatar Yunkang Cao avatar  avatar  avatar Rui Zhang avatar laojian avatar Megamind avatar Shallow avatar KazuhitoTakahashi avatar  avatar  avatar  avatar RU LE avatar  avatar Lazurite avatar 爱可可-爱生活 avatar Jesper Lundgren avatar Mark Peng avatar  avatar nnao45 avatar TakanariShimbo avatar  avatar Xinwei He avatar  avatar undefined avatar  avatar SungHwan Han avatar Hieu Vu avatar Ray avatar Khoa Nguyen avatar bill avatar TRAN Triet avatar Howard H. Tang avatar  avatar  avatar Yuhao Jiang avatar  avatar  avatar Zhongjianmei avatar Andrea Codegoni avatar  avatar  avatar Lujian_Yao avatar Qiyu Chen avatar  avatar  avatar  avatar TOMCAT avatar  avatar  avatar  avatar Howeng avatar  avatar 沈佩雪 avatar  avatar

Watchers

Kostas Georgiou avatar  avatar bill avatar

bgad's Issues

训练过程中,PIX_AUPRO 为-100

你好,我在mvtec数据集上训练,没有更改代码,训练结果的 PIX_AUPRO 都是-100正常吗

Epoch: 24 test_loss: 2.9807
IMG_AUROC: last: 100.00 max: 100.00 epoch_max: 4
PIX_AUROC: last: 99.64 max: 99.67 epoch_max: 21
PIX_AUPRO: last: -100.00 max: -100.00 epoch_max: 0
Saving weights to output/bgad_fas_10/weights/mvtec_tf_efficientnet_b6_conditional_flow_model_hazelnut.pt

关于img_threshold和pixel_threshold

我在自己的数据集上训练模型,但是我想输出二值化结果,于是我再visualizer.py中保存mask,但是输出的mask值全为0;
pixel_threshold=1.98,img_threshold=1.96,这两个值为什么不一样?

Foreground Mask问题咨询

fg_mask前景覆盖的效果很好,但在项目中没有找到对应的算法。
请问能否开源文章中提及的grayscale binary thresholding algorithms,如果不方便可否提供实现思路或伪代码?

custom dataset异常区域定位问题

非常感谢你们的工作!
由于我刚接触异常检测相关知识,有一些问题不理解,想求教一下
我想在我自己的数据集上尝试异常区域的定位,我想问下,想要训练出好的效果,数据集缺陷的groundtruth的mask是否是必须用于监督(因为我自己数据集并没有缺陷部位mask的图片,只是单纯的正常图片和异常图片)
因为我看缺陷部位mask的GT是用于在训练过程中计算bg_sppc loss?我只是为了得到模糊的,而不是精细的异常部位定位输出的话,是否可以不需要用它?

阅读论文有几个疑问?

1、训练时所需要的fg_mask是在确定扩充异常样本的粘贴位置吗,避免缺陷粘贴在背景区域?
2、训练时分为两个阶段,分别是异常边界生成和边界引导,这两个训练过程是同步的吗?
3、选择的课件异常样本数量应该怎么选择呢,mvtec数据集默认每个类别选择10个异常样本,假设我有200个异常样本,3000个正常样本,异常样本数量选择多少呢?

Question about BG-SPP loss

Hi, thank you for the excellent work !
I would like to ask, if we replace the logp term in BG-SPP loss with pair-wise distances, is it equivalent to conventional contrastive loss? Roughly, the BG-SPP loss can be understood as a variation of contrastive loss within the normalized-Flow framework?

how to generate foreground masks

Respected scholars, thank you for your outstanding work.
I would like to know what method was used to generate the foreground masks for the dataset?
My local dataset doesn't have the corresponding masks.

thanks

Questions about hyperparameter Normalizer and Beta.

Hi, Xincheng

Thanks a lot for your great work. When I run your released code, I have questions about the hyperparameter Normalizer and Beta in the code.

I have read and studied the BGAD paper and code carefully, But I didn't find your explanation for the two hyperparameters. Can you give some explanation for the two hyperparameters at your convenience? Or, the values for the two parameters just are the experienced values? Look forward to your reply.

Thanks.
Pengjie

FileNotFoundError: [Errno 2] No such file or directory: 'output/bgad_fas_btad/weights/mvtec_tf_efficientnet_b6_conditional_flow_model_bottle.pt'

After run code for training BTAD,I get output/bgad_fas_btad.But when I run code for testing( python test.py --flow_arch conditional_flow_model --gpu 0 --checkpoint output/bgad_fas_btad --phase test --pro),it occured FileNotFoundError: [Errno 2] No such file or directory:'output/bgad_fas_btad/weights/mvtec_tf_efficientnet_b6_conditional_flow_model_bottle.pt'

custom my own dataset 如何制造我自己的数据集?

非常感谢你们的工作!
由于我刚接触异常检测相关知识,有一些问题不理解,想求教一下
在论文中你提到了elpv数据集,但是在代码中我没有看到如何处理的。我想问下我该如何处理这些数据集得到groundtruth下的那些mask图像呢?
谢谢!

How to use train.sh

When I run "python main.py --flow_arch conditional_flow_model --gpu 0 --data_path /my/dateset/path --with_fas --data_strategy 0,1 --num_anomalies 10 --not_in_test --exp_name bgad_fas_10 --focal_weighting --pos_beta 0.01 --margin_tau 0.1"

It's appear error is that "ValueError: operands could not be broadcast together with shapes (900,900,3) (900,900)"

How to apply about My Customdataset?

First, thank you for your great work.

And I'm a student who study AI.

And I'm trying to apply this code for my custom dataset, but I don't know how to apply.

How to apply about My Custom dataset?

Thank you for reading.

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.