Insightface: verification.py : it uses sum of square of difference between embeddings, NOT the cosine

Created on 19 Oct 2018  路  2Comments  路  Source: deepinsight/insightface

Hello,
In your ReadMe.md, in the section "Pretrained Models", you say that "You can use $INSIGHTFACE/src/eval/verification.py to test all the pre-trained models."

When I look inside this verification.py, it uses this code to compute the score:
diff = np.subtract(embeddings1, embeddings2)
dist = np.sum(np.square(diff),1)

This score is not adapted to SphereFace, CosineFace, ArcFace. For these loss functions, we must use embeddings1.dot_product(embeddings2).

Looking at the header of the verification.py, I see that it is written by David Sandberg - the author of facenet (https://github.com/davidsandberg/facenet). In facenet, I remember that they use TripletLoss and then the score = sum_of_square_of_difference makes sense..

In one of pre-trained model (https://pan.baidu.com/s/1ENjcACInLfBGHZ8e7Fc-XA), I see that the file name is arcface50-caffe (the term "arcface" rings me a bell :) ). Then I guess if I use this trained model, I have to use dot_product to compute the distance between 2 embeddings.

Am I wrong ?

Thanks !

Most helpful comment

I think it's a very simple mathematical transformation with em1 and em2 are both l2 normalized.
(em1 - em2)^2 = em1^2 + em2^2 - 2* dot_product(em1, em2) = 2 - 2 ||em1|| ||em2||cos(theta)=2-2cos(theta)
So euclidean distance has the same meaning with cos distance after normalizing your feature @a2bc

All 2 comments

I think coz of l2 normalized weights you can also use euclidean distance metric.

Can someone explain weight normalisation?

Thank you

I think it's a very simple mathematical transformation with em1 and em2 are both l2 normalized.
(em1 - em2)^2 = em1^2 + em2^2 - 2* dot_product(em1, em2) = 2 - 2 ||em1|| ||em2||cos(theta)=2-2cos(theta)
So euclidean distance has the same meaning with cos distance after normalizing your feature @a2bc

Was this page helpful?
0 / 5 - 0 ratings

Related issues

WIll-Xu35 picture WIll-Xu35  路  3Comments

shenriver picture shenriver  路  5Comments

springtime-cn picture springtime-cn  路  4Comments

AnhVPB picture AnhVPB  路  4Comments

Alloshee picture Alloshee  路  3Comments