hcw-00 / PatchCore_anomaly_detection

Unofficial implementation of PatchCore anomaly detection
Apache License 2.0
317 stars 95 forks source link

Code on computing the anomaly score is inconsistent with the paper #17

Open Youskrpig opened 2 years ago

Youskrpig commented 2 years ago

Hi, Thanks for your work. From formula(6) in paper: image for formula (7) in paper, it should be: image

### "with N_b (m^* ) the b nearest patch-features in M for test patch-feature m^*****

but your code: w = (1 - (np.max(np.exp(N_b))/np.sum(np.exp(N_b)))) I think it's not right

mengxianghan123 commented 2 years ago

I think this line "w = (1 - (np.max(np.exp(N_b))/np.sum(np.exp(N_b))))" should be changed to "w = (1 - (np.min(np.exp(N_b))/np.sum(np.exp(N_b))))". Because S should be the max distance between mtest and its nearest neighbor. N_b is a vector of distance between the chosen mtest and its k-nearest neighbor. So here in this line, we only need to get the smallest distance among k distances, which is the ||mtest - m*||. After changing this line, the performance raise a bit.

JefferyChiang commented 2 years ago

It can be changed to "w = (1 - (np.exp(N_b[0])/np.sum(np.exp(N_b))))" because the N_b is sorted by k. In the other hand, I want to figure out some explanation of why multiply s* by this w can make judge more robust, but still have no idea. Does anyone have any idea of this?

bnascimento commented 2 years ago

It can be changed to "w = (1 - (np.exp(N_b[0])/np.sum(np.exp(N_b))))" because the N_b is sorted by k. In the other hand, I want to figure out some explanation of why multiply s* by this w can make judge more robust, but still have no idea. Does anyone have any idea of this?

I have the same question.