PatchCore anomaly detection

June 28, 2021 · View on GitHub

Unofficial implementation of PatchCore(new SOTA) anomaly detection model

Original Paper : Towards Total Recall in Industrial Anomaly Detection (Jun 2021)
Karsten Roth, Latha Pemula, Joaquin Zepeda, Bernhard Schölkopf, Thomas Brox, Peter Gehler

https://arxiv.org/abs/2106.08265
https://paperswithcode.com/sota/anomaly-detection-on-mvtec-ad

plot

updates(21/06/21) :

  • I used sklearn's SparseRandomProjection(ep=0.9) for random projection. I'm not confident with this.
  • I think exact value of "b nearest patch-features" is not presented in the paper. I just set 9. (args.n_neighbors)
  • In terms of NN search, author used "faiss". but not implemented in this code yet.
  • sample embeddings/carpet/embedding.pickle => coreset_sampling_ratio=0.001

updates(21/06/26) :

  • A critical issue related to "locally aware patch" raised and fixed. Score table is updated.

Usage

# install python 3.6, torch==1.8.1, torchvision==0.9.1
pip install -r requirements.txt

python train.py --phase train or test --dataset_path .../mvtec_anomaly_detection --category carpet --project_root_path path/to/save/results --coreset_sampling_ratio 0.01 --n_neighbors 9'

# for fast try just specify your dataset_path and run
python train.py --phase test --dataset_path .../mvtec_anomaly_detection --project_root_path ./

MVTecAD AUROC score (PatchCore-1%, mean of n trials)

CategoryPaper
(image-level)
This code
(image-level)
Paper
(pixel-level)
This code
(pixel-level)
carpet0.9800.991(1)0.9890.989(1)
grid0.9860.975(1)0.9860.975(1)
leather1.0001.000(1)0.9930.991(1)
tile0.9940.994(1)0.9610.949(1)
wood0.9920.989(1)0.9510.936(1)
bottle1.0001.000(1)0.9850.981(1)
cable0.9930.995(1)0.9820.983(1)
capsule0.9800.976(1)0.9880.989(1)
hazelnut1.0001.000(1)0.9860.985(1)
metal nut0.9970.999(1)0.9840.984(1)
pill0.9700.959(1)0.9710.977(1)
screw0.9640.949(1)0.9920.977(1)
toothbrush1.0001.000(1)0.9850.986(1)
transistor0.9991.000(1)0.9490.972(1)
zipper0.9920.995(1)0.9880.984(1)
mean0.9900.9880.9800.977

Code Reference

kcenter algorithm :
https://github.com/google/active-learning
embedding concat function :
https://github.com/xiahaifeng1995/PaDiM-Anomaly-Detection-Localization-master