deepinsight / insightface

State-of-the-art 2D and 3D Face Analysis Project
https://insightface.ai
22.88k stars 5.35k forks source link

Doubt of can i compare two faces #2199

Open pausiete7 opened 1 year ago

pausiete7 commented 1 year ago

Hi, I have some doubts about how to compare two faces and tell if they are the same person or not. In the documentation I have not found the way to do it but on the web there is a demo that does it, I would like to know how to do it. I would be very grateful if you could solve this doubt for me.

HaithemH commented 1 year ago

Same problem

Johnqxy commented 1 year ago

you can simply calculate the cosine similarity of two vectors

beybars1 commented 1 year ago

Hi, adding to @Johnqxy answer.

The comparison of two faces is done by following:

  1. L-2 normalize two embeddings (vectors). In case of ArcFace, shape of embedding is (512,1)
  2. Calculate cosine similarity of these two embeddings by cos_sim=np.dot(emb1, emb2) (this is the cosine similarity, aka cosine of angle between two vectors)
  3. BONUS, if you are interested in cosine distance, just do this 1-cos_sim
pausiete7 commented 1 year ago

Thanks, I will try it

chhkg commented 1 year ago

What would be the accuracy if comparing untrained faces?

filonenkoa commented 1 year ago

What would be the accuracy if comparing untrained faces?

If you use an already trained model, then the accuracy should be high, provided that you use the same preprocessing technique as in the training data, namely image rectification via facial landmarks.