I want to calculate the similarity or distance of two faces. I'm using Python.

I have read and done what this tutorial says. However, the result is not good (the similarity of same faces and similarity of different faces are very very very close to each other!).

I have downloaded and used this Facenet model to get face embedding vectors, and then used 3 distance metrics (Euclidean, Manhattan, Cosine) to calculate the distance.

After that, I decided to retrain that Facenet model with my dataset. I read this article. I want to use the triplet loss to retrain that Facenet model.

How can I retrain that Facenet model with the triplet loss function? Or can you please send me some links to read?

  • $\begingroup$ Training a network with triplet loss is the same as any other loss, except you use the triplet loss instead of a different loss. What part of training a model with triplet loss is giving you trouble? Do you not know how to compute triplet loss? Are you asking for software to compute triplet loss for you? Or something else? $\endgroup$
    – Sycorax
    May 5 at 14:07

1 Answer 1


If you want to train a model that is similar to Facenet, you have to train a Triplet Loss Neural Network similar to the one that you have seen in the tutorial. After training the full network you have to use only a part of the network that is used for embeddings extraction not the whole network, so when you call model.predict() you will get embeddings as output.

For more theoretical info, you can refer to Andrew NG lecture about it

For practical part, unfortunately there is no too much but hopefully this can help at least for building and using the network.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .