Reimplementation of Towards Total Recall in Industrial Anomaly Detection (Roth et al., 2022), plus a small Gradio app that runs the model as a quality inspection station.
notebooks/patchcore.ipynb follows the paper section by section: locally aware patch features from
a frozen WideResNet-50, greedy coreset subsampling of the memory bank, anomaly scoring and
segmentation, then tables 1, 2, 4 and 5 reproduced on MVTec AD.
Averaged over 6 categories (3 objects, 3 textures) instead of the 15 of the paper, the greedy coreset being quadratic in the number of patches. Paper columns are 15-category averages, so the trend across subsampling ratios matters more than the absolute gap.
| memory bank | AUROC | paper | pixel AUROC | paper | PRO | paper | ms/image |
|---|---|---|---|---|---|---|---|
| 100% | 98.9 | 99.1 | 96.8 | 98.0 | 90.5 | 93.3 | 156 |
| 10% | 99.1 | 99.0 | 97.0 | 98.1 | 91.0 | 93.5 | 38 |
| 1% | 98.9 | 99.0 | 96.9 | 98.0 | 90.6 | 93.1 | 26 |
Larger backbones and ensembles (table 4 of the paper) are covered at the end of the notebook.
The app runs on anomalib rather than on the notebook code, which doubles as a cross-check of the reimplementation against a reference one. Image AUROC / pixel AUROC at 1%, on the six benchmark categories:
| category | notebook | anomalib | paper |
|---|---|---|---|
| bottle | 100.0 / 98.5 | 100.0 / 98.5 | 100.0 / 98.5 |
| capsule | 97.6 / 98.7 | 99.4 / 99.0 | 98.0 / 98.8 |
| grid | 97.9 / 98.4 | 98.3 / 98.2 | 98.6 / 98.6 |
| tile | 99.0 / 95.8 | 100.0 / 95.7 | 99.4 / 96.1 |
| transistor | 100.0 / 94.8 | 99.2 / 96.7 | 99.9 / 94.9 |
| wood | 98.9 / 94.9 | 98.6 / 93.2 | 99.2 / 95.1 |
| average | 98.9 / 96.9 | 99.3 / 96.9 | 99.2 / 97.0 |
uv run app.py
Pick a product category: the first time, its memory bank is fitted and cached under .cache/,
which takes about a minute on a GPU. Then upload an image, or click one of the test samples, to get
a verdict, an anomaly map and the inference time. The decision threshold defaults to the
F1-optimal value found on the validation split, and the slider moves it.
MVTec AD is not included. Download it from
mvtec.com and unpack it into
dataset/, one directory per category. It is released under CC BY-NC-SA 4.0.

