|
| 1 | +# Optimizing PatchCore for Few/many-shot Anomaly Detection |
| 2 | + |
| 3 | +This repository contains the implementation of our paper titled: **["Optimizing PatchCore for Few/many-shot Anomaly Detection"](https://arxiv.org/abs/2307.10792)**. |
| 4 | +We achieve a new state-of-the-art in few-shot Anomaly Detection on Visa by optimizing PatchCore, and furthermore won the the few-shot Anomaly Detection track of the [VAND challenge at CVPR 2023](https://sites.google.com/view/vand-cvpr23/challenge) with this approach. |
| 5 | +Most notably, we leverage a more constrained (i.e. anti-aliased) feature extractor to do this. |
| 6 | +For more details, please check the paper. |
| 7 | + |
| 8 | +<p align="center"> |
| 9 | + <img src="./figures/sota-comparison.png" alt="drawing" width="600"/> |
| 10 | +</p> |
| 11 | + |
| 12 | +## Computing environment |
| 13 | +For our experiments, we used a machine with a Intel(R) Xeon(R) Silver 4110 CPU @ 2.10GHz and a GeForce GTX 1080 Ti GPU with 11GB of VRAM running on the Ubuntu 22.04 OS. |
| 14 | +Parameters like batch size were determined based on this hardware, so feel free to change them. |
| 15 | +The instructions below were made considering an Ubuntu distribution. |
| 16 | + |
| 17 | +By default the code requires having a GPU installed. TO use only CPU, change the parameter `trainer.devices` to `1` inside `src/anomalib/models/config.yaml` |
| 18 | + |
| 19 | +## Installation and running |
| 20 | +* Extract the code into your home directory and change directory: `cd ~/patchcore-few-shot/` |
| 21 | +* (Optional, but recommended) Create a virtual environment with python 3.8, you can use pyenv or another python environment manager. |
| 22 | +* Install dependencies in editable mode: `pip install -e .` |
| 23 | +* The experiments done in the paper can be reproduced by running the bash scripts inside the `experiments` directory. |
| 24 | + |
| 25 | +## Code structure |
| 26 | +We based our code on the open-source package [anomalib](https://github.com/openvinotoolkit/anomalib) and modified it according to our needs. |
| 27 | +Anomalib is a great package with a lot of different algorithms implementation, so do check it out! |
| 28 | + |
| 29 | +``` |
| 30 | +patchcore-few-shot/ |
| 31 | +├── experiments # Bash scripts to reproduce our paper's experiments |
| 32 | +│ |
| 33 | +├── requirements # python package dependencies |
| 34 | +| |
| 35 | +├── scripts # python scripts called in our experiments |
| 36 | +│ |
| 37 | +└── src # main source code |
| 38 | +``` |
| 39 | + |
| 40 | +## Citation |
| 41 | + |
| 42 | +If you find our work useful, please consider citing it |
| 43 | + |
| 44 | +``` |
| 45 | +@misc{santos2023optimizing, |
| 46 | + title={Optimizing PatchCore for Few/many-shot Anomaly Detection}, |
| 47 | + author={João Santos and Triet Tran and Oliver Rippel}, |
| 48 | + year={2023}, |
| 49 | + eprint={2307.10792}, |
| 50 | + archivePrefix={arXiv}, |
| 51 | + primaryClass={cs.CV} |
| 52 | +} |
| 53 | +``` |
0 commit comments