I have face identification system with following details:

  1. VGG16 model for feature extraction
  2. 512 dimensional feature vector (normalized)

I need to calculate similarity measure between two feature vectors. So far I have tried as difference measure:

  1. Pairwise cosine, euclidean distance
  2. Dot product (both vectors are normalize, so their dot product should be in range [-1, 1])

These methods are working fine when I want find closest feature vector from set of Feature Vectors. By sorting difference(distance) measure. But this method is relative measurement.

I want to have percentage of similarity. So I can say given image is Person XXX with degree of certainty of x percentage

Lets say that I have 2 feature vectors ( of person a and b).

I want to calculate accuracy level (in a percentage) that person a is indeed person b, by probability of some percentage.

  • $\begingroup$ Thank you for your post. Can you edit your post to make it explicit what is the question you would like answering? $\endgroup$
    – shepan6
    Jul 24, 2020 at 6:39
  • $\begingroup$ @shepan6 In a nutshell I want some mathematical measure of similarity between 2 feature vectors in a percentage, so I can put threshold like 70-80% $\endgroup$
    – Elbek
    Jul 24, 2020 at 7:16
  • $\begingroup$ you can also use the Kullback-Leibler divergence as similarity measure $\endgroup$
    – Nikos M.
    Jul 25, 2020 at 9:12

2 Answers 2


So, thank you for clarifying the question. Just to confirm that the question is asking how to set an appropriate threshold for face feature vectors (represented a a and b, for example).

What I would recommend is to look at either cosine similarity or euclidean distance, which you have implemented. From here, I would then look the distribution fo the similarity metric over all face vector pairings. Here, this can give you an idea of general level of similarity over all face vector pairings (e.g. if most of the distribution is skewed towards lowers facial similarities, then this could indicate overall lack of similarity between face vector pairings).

If the distribution is skewed to higher similarity values, then you could take, say, the 90th percentile over this distribution as the threshold for determining whether a == b.

Another idea would be to use the idea of softmax in the following way. This method would allow for others to replicate your methodology precisely:

For each face $f_i \in F$, you compute the softmax over the face vector pairings between $f_i$ and $f_j \in F, i \neq j$. Then, from this, you select the index $j$ which has the highest value, which can then be assumed to be such that $f_i$ == $f_j$ (a == b)


So you want to identify a person via the similarity of the feature vector of the faces, with some database of known people, right?

The similarity measures you said will help you identify the person not evaluate the outcome of that identification. To do this you need a set of people, who you know (i.e. are labelled). Then you need to perform your methodology: extract features, measure similarity and identify that person. Then you need to compare this identification with their actual labels. Here is where you can evaluate your performance by measuring the accuracy, precision, recall, etc. of your identification system.

  • $\begingroup$ Thanks @Djib2011, As I said in question I can compare person a's feature vector with set of people using difference measures, but this measures are relative. I want to have exact mathematical or statistical function that measures quantitative similarity measure in a percentage $\endgroup$
    – Elbek
    Jul 24, 2020 at 7:13
  • $\begingroup$ To measure accuracy, though, you need a hard threshold. You can't say that person a is 35% similar to person b and measure accuracy... You need to say that person a is person b, so that you can see if that claim is right or wrong. $\endgroup$
    – Djib2011
    Jul 24, 2020 at 7:17
  • $\begingroup$ Why you can't say I person a is 35% similar to person b? In most of the practices, if person a is similar to person b over some threshold, you would assume that person a is person b. $\endgroup$
    – Elbek
    Jul 24, 2020 at 7:33
  • $\begingroup$ When wanting to measure accuracy, you can't. You need to set a threshold, compare the percentage to the threshold and say either a is b or a isn't b. You need this in order to then see if you're right or wrong. $\endgroup$
    – Djib2011
    Jul 24, 2020 at 7:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.