Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ghost opened this issue Jul 31, 2022 · 3 comments
Closed

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

ghost opened this issue Jul 31, 2022 · 3 comments

Comments

@ghost
Copy link

ghost commented Jul 31, 2022

Thanks to your efforts,
I've noticed in the code of patchcore,
doing k nearest neighbor search,

_, nn_idx = torch.topk(w_dist, k=self.n_reweight, largest=False) # pt.2

the value of k is set to 3,
can I ask how to determine the value of k?
can I set k=1?

@rvorias
Copy link
Owner

rvorias commented Aug 1, 2022

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.

@rvorias rvorias closed this as completed Aug 1, 2022
@ghost
Copy link
Author

ghost commented Aug 1, 2022

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
Copy link
Owner

rvorias commented Aug 1, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant