GithubHelp home page GithubHelp logo

plutoyuxie / reconstruction-by-inpainting-for-visual-anomaly-detection Goto Github PK

View Code? Open in Web Editor NEW
88.0 3.0 20.0 790 KB

This is an unofficial implementation of Reconstruction by inpainting for visual anomaly detection (RIAD).

Jupyter Notebook 94.38% Python 5.62%
reconstruction mvtec-ad unsupervised-anomaly-detection unet anomaly-detection anomaly-localization anomaly-segmentation

reconstruction-by-inpainting-for-visual-anomaly-detection's Introduction

Reconstruction by Inpainting for visual Anomaly Detection (RIAD) in PyTorch

This is an unofficial implementation of Reconstruction by inpainting for visual anomaly detection (RIAD).

PipeLine

avatar

Prerequisites

  • PyTorch 1.5
  • sklearn, matplotlib
  • kornia ( incompatible with PyTorch>=1.6.0 so far )
    The kornia package is used for its medianfilter function. You may find a substitution if you want to get rid of this dependency.

Visualization demo of randomly generated mosaic masks

Please check this mosaic.ipynb file

Usage

To train RIAD on MVTec AD dataset:

python train.py --obj zipper --data_path [your-mvtec_ad-data-path]

Then to test:

python test.py --obj zipper --data_path [your-mvtec_ad-data-path] --checkpoint_dir [your-saved-weights-path]

Finally, you will get results like img_ROCAUC (anomaly detection) around 0.97 and pixel_ROCAUC (anomaly segmetation) around 0.98

Localization results

avatar

References

Vitjan Zavrtanik, Matej Kristan, Danijel Skčaj,
Reconstruction by inpainting for visual anomaly detection,
Pattern Recognition,
2020,
107706,
ISSN 0031-3203

Acknowledgement

Thanks for the paper authors.
A big thanks to xiahaifeng1995 for contributing most of the codes.

reconstruction-by-inpainting-for-visual-anomaly-detection's People

Contributors

plutoyuxie avatar xiahaifeng1995 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

reconstruction-by-inpainting-for-visual-anomaly-detection's Issues

train

Hello, I use my own data set, the format of the data set is also correct, but an error is reported
image

NaN after few steps loss

Hi, thanks for posting these codes.
I'm trying to replicate the results, but I'm getting NaN after 11 steps.
I installed all the dependencies in the described versions, but I still have these results.
Please find below the log results

$ python train.py --obj zipper --data_path ./data/mvtech_anomaly --batch_size 2  

{'alpha': 1.0, 'batch_size': 2, 'belta': 1.0, 'data_path': ' ./data/mvtech_anomaly', 'data_type': 'mvtec', 'epochs': 300, 'gamma': 1.0, 'grayscale': False, 'img_size': 256, 'input_channel': 3, 'k_value': [2, 4, 8, 16], 'lr': 0.0001, 'obj': 'zipper', 'prefix': '2020-12-03-1197', 'save_dir': './mvtec/zipper/seed_2988/', 'seed': 2988, 'validation_ratio': 0.2, 'weight_decay': 1e-05}
   1/300 ----- [[2020-12-03 23:30:45]] [Need: 00:00:00]
  0%|                                                                                                         | 0/96 [00:00<?, ?it/s]Step Loss: 1.779465
  1%|█                                                                                                | 1/96 [00:02<03:22,  2.13s/it]Step Loss: 1.835103
  2%|██                                                                                               | 2/96 [00:03<02:52,  1.83s/it]Step Loss: 1.479402
  3%|███                                                                                              | 3/96 [00:04<02:36,  1.69s/it]Step Loss: 1.401773
  4%|████                                                                                             | 4/96 [00:05<02:26,  1.59s/it]Step Loss: 1.448756
  5%|█████                                                                                            | 5/96 [00:07<02:13,  1.46s/it]Step Loss: 1.693701
  6%|██████                                                                                           | 6/96 [00:08<02:02,  1.36s/it]Step Loss: 1.229446
  7%|███████                                                                                          | 7/96 [00:09<02:00,  1.36s/it]Step Loss: 1.215524
  8%|████████                                                                                         | 8/96 [00:10<02:00,  1.36s/it]Step Loss: 1.493567
  9%|█████████                                                                                        | 9/96 [00:12<01:52,  1.29s/it]Step Loss: 1.430892
 10%|██████████                                                                                      | 10/96 [00:13<01:46,  1.24s/it]Step Loss: 1.118710
 11%|███████████                                                                                     | 11/96 [00:14<01:48,  1.28s/it]Step Loss: nan
 12%|████████████                                                                                    | 12/96 [00:15<01:43,  1.23s/it]Step Loss: nan
 14%|█████████████                                                                                   | 13/96 [00:16<01:41,  1.22s/it]

Gradient Magnitude Map

The gradient magnitude map is defined as
$g(\mathbf{I}) = \sqrt{(\mathbf{I} * \mathbf{h}_x) + (\mathbf{I} * \mathbf{h}_y)}$

Why are you using g_I = edge_filter(median_filter(x)) in lines 35 and 36 in gms_loss.py instead?

outputs all Nan when test

Thanks for providing this code
With the mvyec dataset bottle, the training proceeds seccessful.
but when running test.py
“outputs = [model(x) for x in inputs]”
image
show Error: Input contains NaN, infinity or a value too large for dtype('float32').
please tell me the reason .I didn't modify the code. maybe get model.pt with any problems?
thanks

About testing.

Thanks for providing the nice code.

With my custom dataset, the training proceeds without any problems.

But when running the test
image
i have a problem like the picture above.

If it's a problem with the number of channels, then learning shouldn't be happening, but what is the reason that learning is progressing, but only testing is not progressing?

using gpu for training. test any image

i set up gpu for training on colab but why don't your model use gpu?
i can't test any image without it's mask. can i reslove this problem?
please help me
thank you

my own data

Hello, thank you for your excellent work, how can I use my own data and training network

About custom data.

Thank you for providing a really interesting code.

Train, test, ground_truth were all resized to 500X500 and inserted into each directory.
However, the error below appears.

RuntimeError: stack expects each tensor to be equal size, but got [1, 256, 256] at entry 0 and [3, 256, 256] at entry 1

Can you tell me what the problem is?

Data issues

image
Hello, when I train with my own dataset, there is no problem, but when I test it, the following problem appears, what can I do to correct it, thank youuuuu~

The evaluation results are not the same as the paper

cable_roc_curve
bottle_roc_curve
Great author, hello, I have a question that without changing any parameter configuration, the results of the bottle test are similar to the results of the paper, but the results of the cable test are slightly different from the results of the paper. Which step is the problem? Please help me, thanks a lot

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.