talreiss / Mean-Shifted-Anomaly-Detection

Mean-Shifted Contrastive Loss for Anomaly Detection (AAAI 2023)
https://arxiv.org/pdf/2106.03844.pdf
Other
117 stars 23 forks source link

A question about Anomaly criterion. #9

Closed Mengyuan-Zhao closed 2 years ago

Mengyuan-Zhao commented 2 years ago

Your work is really great!I have a question about anomaly criterion in your code. In your paper, there be :

In order to classify a sample as normal or anomalous, we use a simple criterion based on kNN using the cosine distance. We first compute the cosine distance between the features of the target image x and those of all training images.

but in this code, I coud not find anything about this part. The knn_score function is the same as PANDA. So I am confused. Is there a part in the code to calculate the cosine distance? def knn_score(train_set, test_set, n_neighbours=2): index = faiss.IndexFlatL2(train_set.shape[1]) index.add(train_set) D, _ = index.search(test_set, n_neighbours) return np.sum(D, axis=1)

Hope for your reply. Thanks!

talreiss commented 2 years ago

Hi Please note that the Euclidean metric when dealing with unit vectors is proportional to the cosine distance multiplied by a constant factor. Therefore, this process is equivalent. Hope this clarifies your questions.

Mengyuan-Zhao commented 2 years ago

Hi Please note that the Euclidean metric when dealing with unit vectors is proportional to the cosine distance multiplied by a constant factor. Therefore, this process is equivalent. Hope this clarifies your questions.

Thank you!