C4 W4 A1: Programming Assignment: Face Recognition UNQ_C1 possibly wrong unit test answer

UNQ_C1 is for programming the triplet loss function

I may be wrong in what the flow of computing it is but from what I understand.
the triplet loss is computed as followed

max\left(\left[\sum_{m=1}^{M}{\left(\sum_{i=1}^{N}{(A^m_i - P^m_i)^2} - \sum_{i=1}^{N}{(A^m_i - N^m_i)^2} + \alpha\right)}, 0\right]\right)
where M is the examples in the batch and N is the features

upon running the tests, all passed except the last one which shows
for M=2 where the basic loss of the batch is [5, -2] the correct loss is 5 instead of 3, therefore the correct equation for the triplet loss should be
max\left(\left[max\left(\sum_{i=1}^{N}{(A^m_i - P^m_i)^2} - \sum_{i=1}^{N}{(A^m_i - N^m_i)^2} + \alpha\right), 0\right]\right)

however, adapting the code where loss is calculated to
results in a earlier unit test to fail, whch can be seen where
for M=2 where basic loss of the batch is [1, 1], the correct loss is 2, which is contradictory to what the last unit test states

For the basic_loss calculation, please use tf.add() and tf.subtract().
For loss, you might need to reverse the order of the functions you’re using.

Please, do not post your code on the forum. That isn’t allowed by the code of conduct.

Thank you, the problem was the later, I though that it was a summation of all losses calculated and then a max instead of it being the max element wise to make sure no negative values where added into the loss.

1 Like