Answers.Body: <p>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 <code>model.predict()</code> you will get embeddings as output.</p>
  <p>For more theoretical info, you can refer to Andrew NG lecture about it</p>
  <p>For practical part, unfortunately there is no too much but hopefully <a href="https://www.kaggle.com/ashishpatel26/triplet-loss-network-for-humpback-whale-prediction" rel="nofollow noreferrer">this</a> can help at least for building and using the network.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-07-19T11:50:50.353Z
Answers.LastActivityDate: 2021-07-19T11:50:50.353Z
Answers.UserDisplayName: Mohammed Abed
Body: <p>I want to calculate the similarity or distance of two faces. I'm using Python.</p>
  <p>I have read and done what this <a href="https://machinelearningmastery.com/how-to-develop-a-face-recognition-system-using-facenet-in-keras-and-an-svm-classifier/" rel="nofollow noreferrer">tutorial</a> 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!).</p>
  <p>I have downloaded and used <a href="https://drive.google.com/file/d/1PZ_6Zsy1Vb0s0JmjEmVd8FS99zoMCiN1/view?usp=sharing" rel="nofollow noreferrer">this</a> Facenet model to get face embedding vectors, and then used 3 distance metrics (Euclidean, Manhattan, Cosine) to calculate the distance.</p>
  <p>After that, I decided to retrain that Facenet model with my dataset. I read this <a href="https://medium.com/@mohitsaini_54300/train-facenet-with-triplet-loss-for-real-time-face-recognition-a39e2f4472c3" rel="nofollow noreferrer">article</a>. I want to use the triplet loss to retrain that Facenet model.</p>
  <p>How can I retrain that Facenet model with the triplet loss function? Or can you please send me some links to read?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-05-05T14:07:35.377Z
Comments.Text: 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?
Comments.UserDisplayName: Sycorax
Tags: <deep-learning><python><facenet><triplet-loss-function>
Title: How to retrain a Facenet model with the triplet loss function?
UserDisplayName: behrad
ThreadText: # How to retrain a Facenet model with the triplet loss function?
  
  (Asked by: username_0 on 2021-05-22)
  
  I want to calculate the similarity or distance of two faces. I'm using Python.
  
  I have read and done what this [tutorial](https://machinelearningmastery.com/how-to-develop-a-face-recognition-system-using-facenet-in-keras-and-an-svm-classifier/) 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](https://drive.google.com/file/d/1PZ_6Zsy1Vb0s0JmjEmVd8FS99zoMCiN1/view?usp=sharing) 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](https://medium.com/@mohitsaini_54300/train-facenet-with-triplet-loss-for-real-time-face-recognition-a39e2f4472c3). 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?
  
  **Tags:** deep-learning, python, facenet, triplet-loss-function
  > **Comments:**
  > **username_1**: 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?  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2021-07-19. Score: 0
  
  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](https://www.kaggle.com/ashishpatel26/triplet-loss-network-for-humpback-whale-prediction) can help at least for building and using the network.
  
  
  ---
  
  