Giter VIP home page Giter VIP logo

mlf-sc's Introduction

MLF-SC: Incorporating Multi-Layer Features to Sparse Coding for Unsupervised Anomaly Detection

Actions Status Maintainability

MLF-SC (Multi-Layer Feature Sparse Coding) is an anomaly detection method that incorporates multi-scale features to sparse coding. This is a PyTorch implementation for MVTec datasets (Carpet, Grid, Leather, Tile, Wood, ...).

Output visualization of MVTec dataset (Grid, Hazelnut, and Bottle)

001-447078 010-390276 018-341679

Quick Start

git clone [email protected]:LeapMind/MLF-SC.git
pip3 install -r requirements.txt
python3 main.py train cfg/sample_config.yml
python3 main.py test cfg/sample_config.yml

Download Dataset

wget ftp://guest:[email protected]/mvtec_anomaly_detection/mvtec_anomaly_detection.tar.xz
tar -xvf mvtec_anomaly_detection.tar.xz 

Usage

You can train and test for each texture dataset.

Set dataset path to config.yml

Set root in config.yml to texture dataset path (like path/to/mvtec_anomaly_detection/carpet/).

Train

$ python3 main.py train cfg/config.yml

Test and Visualize Output

$ python3 main.py test cfg/config.yml

Contribution

Anomaly detection performance for the texture categories of the MVTec AD dataset. For each cell in the R1 / R2 columns, the ratio of correctly classified samples of normal R1 and that of anomalous images R2 are shown with R1 / R2 notation. The maximum averages (R1 + R2) / 2 are marked with boldface. The performance for the non-sparse-coding-based methods are cited from Table 2 of (Bergmann et al., 2019). The AUROC columns show only sparse coding and MLF-SC.

R1 / R2 AUROC
Category AE (SSIM) AE (L2) AnoGAN CNN
Feature Dictionary
Texture
Inspection
Sparse
Coding
MLF-SC
(Proposed)
Sparse
Coding
MLF-SC
(Proposed)
Carpet 0.43 / 0.90 0.57 / 0.42 0.82 / 0.16 0.89 / 0.36 0.57 / 0.61 0.43 / 0.79 1.00 / 0.98 0.58 0.99
Grid 0.38 / 1.00 0.57 / 0.98 0.90 / 0.12 0.57 / 0.33 1.00 / 0.05 0.76 / 0.72 1.00 / 0.88 0.89 0.97
Leather 0.00 / 0.92 0.06 / 0.82 0.91 / 0.12 0.63 / 0.71 0.00 / 0.99 0.84 / 0.96 0.97 / 0.97 0.95 0.99
Tile 1.00 / 0.04 1.00 / 0.54 0.97 / 0.05 0.97 / 0.44 1.00 / 0.43 0.94 / 0.60 0.94 / 0.76 0.86 0.92
Wood 0.84 / 0.82 1.00 / 0.47 0.89 / 0.47 0.79 / 0.88 0.42 / 1.00 0.84 / 0.60 0.95 / 0.98 0.97 0.99
Average 0.53 / 0.74 0.64 / 0.65 0.90 / 0.18 0.77 / 0.54 0.60 / 0.62 0.76 / 0.81 0.97 / 0.91 0.85 0.97

License

Non-commercial, research purposes only

License of dependent libraries

See LICENSE directory.

mlf-sc's People

Contributors

a-hanamoto avatar minux302 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

Watchers

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

mlf-sc's Issues

GPU utilization

First of all thanks for the work.

I was trying to use the test section for the prediction of anomalies from the dataset. The time taken for prediction is too long.

Is there any option for utilizing GPU with the code that can improve the execution time?

about calculate_score()

Hi, execuse me. I really wonder know that how you use calculate_score(neg_err, pos_err) to classify the images, especially the usage of y_score? Thank you so much.

DefaultCPUAllocator: not enough memory: you tried to allocate 16777216000 bytes. Buy new RAM!

When I run 'python main.py train cfg/sample_config.yml '
and even set batch_size==1,
the issue raised as follows:

loading images: 99%|█████████████████████████████████████████████████
loading images: 100%|█████████████████████████████████████████████████
loading images: 100%|█████████████████████████████████████████████████
█████████████| 1000/1000 [00:18<00:00, 54.16it/s]
Traceback (most recent call last):
File "main.py", line 109, in
main()
File "main.py", line 74, in main
model.train()
File "D:\research\comp_data\MLF-SC\src\models.py", line 53, in train
batch_img = p(batch_img)
File "D:\research\comp_data\MLF-SC\src\preprocessor.py", line 95, in call
x = f(x)
File "D:\anaconda\lib\site-packages\torch\nn\modules\module.py", line 541, in call
result = self.forward(*input, **kwargs)
File "D:\anaconda\lib\site-packages\torch\nn\modules\conv.py", line 345, in forward
return self.conv2d_forward(input, self.weight)
File "D:\anaconda\lib\site-packages\torch\nn\modules\conv.py", line 342, in conv2d_forward
self.padding, self.dilation, self.groups)
RuntimeError: [enforce fail at ..\c10\core\CPUAllocator.cpp:72] data. DefaultCPUAllocator: not enough memory: you tried
to allocate 16777216000 bytes. Buy new RAM!

Well, would you figure out the way to solve this issue?
Thank you in advance!

About R1 and R2

First of all, thanks for the great work. Can you tell how to get the R1 and R2 mentioned in this paper? Actually, I can just get AP and AUC in the code. There is no way to get R1 and R2. Sorry to bother you~

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.