rvorias / ind_knn_ad

Vanilla torch and timm industrial knn-based anomaly detection for images.
https://share.streamlit.io/rvorias/ind_knn_ad
MIT License
147 stars 50 forks source link

Patchcore: the value of k in nearest neighbor search #28

Closed ghost closed 2 years ago

ghost commented 2 years ago

Thanks to your efforts, I've noticed in the code of patchcore, doing k nearest neighbor search, https://github.com/rvorias/ind_knn_ad/blob/5510f0f4bc1fc9688e57d20023985087f90f0f4d/indad/models.py#L286 the value of k is set to 3, can I ask how to determine the value of k? can I set k=1?

rvorias commented 2 years ago

Thanks for your question. I believe I got 3 from the original paper. The best k depends on your dataset and your validation performance. You can indeed set k=1.

ghost commented 2 years ago

Thanks to your explanation, I'm confused because two other implementations anomalib and hcw-00 they both set the value of k to 9.

Fig.4 top in the paper, I'm not sure the 'neighborhood size' here is refer to the local neighborhood aggregation part (the Avgpool operation) or the k neighbor search operation...

rvorias commented 2 years ago

I've always interpreted the local neighborhood aggregation part as avgpool part.