This question is related to What is the formula used to calculate the accuracy in the FaceNet model? . I know how loss is calculated in the FaceNet model , but how the loss function is used to calculate probability that this unknown person is , say Bob (0.70). Also we don't know which is positive or negative image , we only know the Anchor (so how FaceNet finds which image is positive or negative ?) . How probability is calculated in FaceNet Model using triplet loss ?

Can we know what is the exact formula or CNN is like black box which uses some unknown method to calculate probability ?


The facenet model is just the head of the model. The architecture is similar to the enocdr part of an autoencoder, but it uses supervised learning instead of unsupervised learning. The network is called a siamese network The triplet loss helps make the embeddings more representative of the input image/person, with the embedding distance being as large as possible for difference people and vice versa.

However the embeddings is just the representation of the people. It doesn't contain information directly mapping to what person it is. The classification head is used after the Face Net feature extraction top is used.

One-shot learning method for person classfication

This method saves the calculated embeddings of people in a database. The face recognition system first calculates the embeddings of the new, unknown image to be classified. The system loop through the embeddings database and calculates the Euclidean distance of the unknown embeddings and the embeddings in the database.

After computing, it chooses the smallest distance of all and compares it to a threshold set by you. If the distance is larger than the threshold, the classified class is unknown , or else the resulting class will be the embeddings which results to the lowest distance.

Example code from the deeplearning.ai coursera course (great course on AI btw): Example code of one shot face recognition

Advantages and disadvantages of the system

The system have advantages ranging from no training needed and can classify unknown class. However, once the number of people in the database becomes huge, the system will run slower. It's performance may also differ depending on the quality of the reference image.

SVM (Support Vector Machine) method

This is the method used in the github repository of your previous posts. It uses a one layer nn classifying head to output the classified class.

Advantages and disadvantages of the system

The system have the flexibility of adapting to multiple photo environment and no affecting of performance due to reference images. This method also works well for larger database of people. Triplet loss can also be removed using this method. You can train the network directly from propagating the loss with the probability predicted. However, This method requires re-training when a new person is added to the system. Multiple images of a person is also needed.

  • $\begingroup$ Just one more doubt , SVM classifies (0 or 1) but does not returns probability but method used in GitHub repository returns probability ? $\endgroup$ – TheReal__Mike Nov 12 '19 at 16:28
  • $\begingroup$ can SVM return probability also ? $\endgroup$ – TheReal__Mike Nov 12 '19 at 16:29
  • $\begingroup$ Can you tell what method that repository uses to convert classification to probability ? $\endgroup$ – TheReal__Mike Nov 12 '19 at 16:52
  • $\begingroup$ Also what is relation between SVM and triplet Loss ? $\endgroup$ – TheReal__Mike Nov 12 '19 at 16:55
  • $\begingroup$ For the first question, the SVM return a confidence value from 0 to 1, with 1 being most confidence and 0 being not. It does not return an integer value. The probability of the repository is the probability of the most confidence class. $\endgroup$ – Clement Hui Nov 13 '19 at 0:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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