This is an unofficial implementation of the paper Towards Total Recall in Industrial Anomaly Detection.

We measured accuracy and speed for percentage_coreset=0.01, 0.1 and 0.25.
This code was implimented with patchcore-inspection, thanks.
Some "ex" are explainability, express delivery, flexibility, extra algolithm and so on.
- faiss-gpu (easy to install with conda : ref)
- torch
- torchvision
- numpy
- opencv-python
- scipy
- argparse
- matplotlib
- scikit-learn
- torchinfo
- tqdm
Install prerequisites with:
conda install --file requirements.txt
Please download MVTec AD dataset.
After downloading, place the data as follows:
./
├── main.py
└── mvtec_anomaly_detection
├── bottle
│ ├── ground_truth # pixel annotation of test data other than good
│ │ ├── broken_large
│ │ ├── broken_small
│ │ └── contamination
│ ├── test # other than good is anomaly data
│ │ ├── broken_large
│ │ ├── broken_small
│ │ ├── contamination
│ │ └── good
│ └── train # good only
│ └── good
├── cable
├── cable
├── capsule
├── carpet
├── grid
├── hazelnut
├── leather
├── metal_nut
├── pill
├── screw
├── tile
├── toothbrush
├── transistor
├── wood
└── zipper
When using custom dataset, place the data as follows:
./
├── main.py
└── custom_data
└── theme
├── ground_truth # pixel annotation of test data other than good
│ ├── anomaly_type_a
│ └── anomaly_type_b
├── test # other than good is anomaly data
│ ├── anomaly_type_a
│ ├── anomaly_type_b
│ └── good
└── train # good only
└── good
To test PatchCore on MVTec AD dataset:
python main.py
After running the code above, you can see the ROCAUC results in result/roc_curve.png
To test PatchCore on custom dataset:
python main.py --path_data ./custom_data
Below is the implementation result of the test set ROCAUC on the MVTec AD dataset.
| Paper |
This Repo |
This Repo |
This Repo |
|
|---|---|---|---|---|
| bottle | 100.0 | 100.0 | 100.0 | 100.0 |
| cable | 99.4 | 99.6 | 99.9 | 99.6 |
| capsule | 97.8 | 97.6 | 97.8 | 97.8 |
| carpet | 98.7 | 98.3 | 98.7 | 98.5 |
| grid | 97.9 | 97.8 | 98.5 | 98.4 |
| hazelnut | 100.0 | 100.0 | 100.0 | 100.0 |
| leather | 100.0 | 100.0 | 100.0 | 100.0 |
| metal_nut | 100.0 | 100.0 | 100.0 | 99.9 |
| pill | 96.0 | 96.3 | 96.2 | 96.4 |
| screw | 97.0 | 97.9 | 98.5 | 98.1 |
| tile | 98.9 | 99.0 | 99.4 | 99.2 |
| toothbrush | 99.7 | 99.4 | 99.4 | 100.0 |
| transistor | 100.0 | 99.8 | 100.0 | 100.0 |
| wood | 99.0 | 99.1 | 99.0 | 98.9 |
| zipper | 99.5 | 99.7 | 99.6 | 99.5 |
| Average | 99.0 | 99.0 | 99.1 | 99.1 |
| Paper |
This Repo |
This Repo |
This Repo |
|
|---|---|---|---|---|
| bottle | 98.6 | 98.5 | 98.6 | 98.6 |
| cable | 98.5 | 98.2 | 98.4 | 98.4 |
| capsule | 98.9 | 98.8 | 98.9 | 98.9 |
| carpet | 99.1 | 99.0 | 99.1 | 99.0 |
| grid | 98.7 | 98.2 | 98.7 | 98.7 |
| hazelnut | 98.7 | 98.6 | 98.7 | 98.6 |
| leather | 99.3 | 99.3 | 99.3 | 99.3 |
| metal_nut | 98.4 | 98.5 | 98.7 | 98.7 |
| pill | 97.6 | 97.4 | 97.6 | 97.3 |
| screw | 99.4 | 98.8 | 99.4 | 99.4 |
| tile | 95.9 | 96.2 | 96.1 | 95.9 |
| toothbrush | 98.7 | 98.6 | 98.7 | 98.7 |
| transistor | 96.4 | 94.2 | 96.0 | 95.8 |
| wood | 95.1 | 95.7 | 95.5 | 95.4 |
| zipper | 98.9 | 98.9 | 98.9 | 98.9 |
| Average | 98.1 | 97.9 | 98.2 | 98.1 |
| This Repo |
This Repo |
This Repo |
|
|---|---|---|---|
| bottle | 14.2 | 21.3 | 33.0 |
| cable | 22.9 | 30.3 | 44.6 |
| capsule | 20.4 | 27.3 | 39.8 |
| carpet | 22.4 | 32.6 | 52.7 |
| grid | 16.3 | 26.3 | 44.3 |
| hazelnut | 25.9 | 46.4 | 82.1 |
| leather | 20.8 | 28.5 | 44.0 |
| metal_nut | 16.8 | 23.8 | 36.3 |
| pill | 23.3 | 34.2 | 52.6 |
| screw | 22.4 | 37.7 | 63.9 |
| tile | 18.4 | 26.2 | 40.7 |
| toothbrush | 5.8 | 6.7 | 8.0 |
| transistor | 17.2 | 23.9 | 35.9 |
| wood | 18.0 | 26.5 | 42.1 |
| zipper | 20.5 | 29.0 | 44.2 |
CPU : Intel(R) Xeon(R) Gold 6148 CPU @ 2.40GHz
GPU : Tesla V100 SXM2
We also implement a similar algorithm, SPADE.
https://github.com/any-tech/SPADE-fast/tree/main
There is an explanatory article.
https://tech.anytech.co.jp/entry/2023/03/24/100000
































