Coder Social home page Coder Social logo

mahalanobisad-pytorch's Introduction

Modeling the Distribution of Normal Data in Pre-Trained Deep Features for Anomaly Detection in PyTorch

PyTorch implementation of Modeling the Distribution of Normal Data in Pre-Trained Deep Features for Anomaly Detection.

This paper presents an anomaly detection approach that consists of fitting a multivariate Gaussian to normal data in the pre-trained deep feature representations, using Mahalanobis distance as anomaly score.
It is a simple yet effective approach and achieves SOTA on MVTec AD dataset.

Prerequisites

  • python 3.6+
  • PyTorch 1.5+
  • efficientnet_pytorch == 0.6.3
  • sklearn, matplotlib

Install prerequisites with:

pip install -r requirements.txt

If you already download MVTec AD dataset, move a file to data/mvtec_anomaly_detection.tar.xz.
If you don't have a dataset file, it will be automatically downloaded during the code running.

Usage

To test this implementation code on MVTec AD dataset:

cd src
python main.py

After running the code above, you can see the ROCAUC results in src/result/roc_curve_{model_name}.png

Results

Below is the implementation result of the test set ROCAUC on the MVTec AD dataset.

Paper Implementation
bottle - 100.0
cable - 94.2
capsule - 92.3
carpet - 98.1
grid - 94.6
hazelnut - 98.6
leather - 100.0
metal_nut - 94.3
pill - 83.4
screw - 78.1
tile - 98.6
toothbrush - 96.7
transistor - 96.1
wood - 98.5
zipper - 97.7
Average 94.8 94.7

ROC Curve

roc

mahalanobisad-pytorch's People

Contributors

byungjae89 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

mahalanobisad-pytorch's Issues

How to calculate the threshold value?

Thank you very much for your excellent work!
In the evaluation part of your code, only the auroc part is calculated. If it is used in inference, how to calculate the threshold of anomaly detection?

when running efficientnet-b0, error occurs

Loaded pretrained weights for efficientnet-b0
| feature extraction | train | bottle |: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 7/7 [00:32<00:00, 4.58s/it]
Traceback (most recent call last):
File "main.py", line 150, in
main()
File "main.py", line 66, in main
mean = torch.mean(torch.cat(train_output, 0).squeeze(), dim=0).cpu().detach().numpy()
RuntimeError: There were no tensor arguments to this function (e.g., you passed an empty list of Tensors), but no fallback function is registered for schema aten::_cat. This usually means that this function requires a non-empty list of Tensors. Available functions are [CPU, CUDA, QuantizedCPU, Autograd, Profiler, Tracer, Autocast]

The results are different from yours

@byungjae89 I have test the code,but I cant get the results.
bottle ROCAUC: 1.000
cable ROCAUC: 0.940
capsule ROCAUC: 0.923
carpet ROCAUC: 0.955
grid ROCAUC: 0.929
hazelnut ROCAUC: 0.987
leather ROCAUC: 1.000
metal_nut ROCAUC: 0.931
pill ROCAUC: 0.834
screw ROCAUC: 0.812
tile ROCAUC: 0.974
toothbrush ROCAUC: 0.958
transistor ROCAUC: 0.959
wood ROCAUC: 0.976
zipper ROCAUC: 0.979
Average ROCAUC: 0.944

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.