C3W3 Triplet Loss value is wrong

I think my function to calculate negative_zero_on_duplicate is wrong due to the shape (may be batch size include). The comment of suggestion “subtract the diagonal from scores”. It’s mean I have to subtract the scores with positive right ?


Hello @skinx.learning

you have incorrect codes for

  1. use tf.linalg.matmul to take the dot product of the two batches.
    Don’t forget to transpose the second argument using transpose_b=True
    YOU HAVE USED MARGIN, NOT REQUIRED. ALSO THE TWO BATCHES, need to be mentioned as v2, v1 and not v1, v2

2.subtract the diagonal from scores. You can do this by creating a diagonal matrix with the values of all positive examples using tf.linalg.diag
FOR THIS CODE LINE YOU ARE SUPPOSE TO SUBSTRACT tf.linglg.diag of positive examples(recalled before use tf.linalg.diag_part to grab the cosine similarity of all positive examples) from scores.

Kindly use the search engine, there are many threads related to triplet loss where you will find solution to your problem.

Regards
DP

  1. Actually I use solution code removed ) Is this the same as what you mentioned ?
1 Like

send me your codes via DM

Thank you! i had not though of checking the very first code on the order of the v’s.

1 Like