Course 4 Week 4 project 1

Gotcha. Well i really appreciate the help. I figured you guys had recently switched to a new platform or release, since tensorflow version 2.5.0, and 2.4 was just made stable in January. From what I can tell from the google, it looks like 2.5.0 was just released like a week ago?

Ya, that seems like it should suffice the, you could also figure out what comes out when you do it backwards, and do a negative assertion on it, to make sure people are not doing that. Also, if you put in a different axis like 0. Cuz that said it passed also. Do a negative assertion on its output value.

1 Like

tf.Tensor([3122.1926 3377.6548 3365.9343], shape=(3,), dtype=float32)
tf.Tensor([3122.1926 3377.6548 3365.9343], shape=(3,), dtype=float32)
loss = tf.Tensor(0.6, shape=(), dtype=float32)
tf.Tensor(0.0, shape=(), dtype=float32)
tf.Tensor(0.0, shape=(), dtype=float32)
tf.Tensor(0.0, shape=(), dtype=float32)
tf.Tensor(0.0, shape=(), dtype=float32)

AssertionError Traceback (most recent call last)
in
14 y_pred_perfect = ([1., 1.],[1., 1.], [0., 0.,])
15 loss = triplet_loss(y_true, y_pred_perfect, 3)
ā€”> 16 assert loss == 1., ā€œWrong value. Check that pos_dist = 0 and neg_dist = 2 in this exampleā€
17 y_pred_perfect = ([1., 1.],[0., 0.], [1., 1.,])
18 loss = triplet_loss(y_true, y_pred_perfect, 0)

AssertionError: Wrong value. Check that pos_dist = 0 and neg_dist = 2 in this example

Hi I am getting this errorā€¦what i could be doing wrong?

@Adlino: I added more print statements to my triplet_loss function and hereā€™s the output I get for the test block in the notebook:

pos_dist = [3122.1926 3377.6548 3365.9343]
neg_dist = [3905.9553 2850.595  3434.0498]
basic_loss = [-783.5627   527.2598   -67.91548]
loss = tf.Tensor(527.2598, shape=(), dtype=float32)
pos_dist = 0.0
neg_dist = 0.0
basic_loss = 5.0
pos_dist = 0.0
neg_dist = 2.0
basic_loss = 1.0
pos_dist = 2.0
neg_dist = 0.0
basic_loss = 2.0
pos_dist = 0.0
neg_dist = 0.0
basic_loss = -2.0
pos_dist = [0. 0.]
neg_dist = [2. 2.]
basic_loss = [1. 1.]

So your first value agrees with mine for pos_dist, but what is the second value?

1 Like

Oh my god! I was stuck at this for such a long time until i realised what was written. Thank you for this !

1 Like

these were my values

pos dist tf.Tensor([3122.1926 3377.6548 3365.9343], shape=(3,), dtype=float32)
neg dist tf.Tensor([3905.9553 2850.595 3434.0498], shape=(3,), dtype=float32)
basic loss tf.Tensor([-783.5627 527.2598 -67.91548], shape=(3,), dtype=float32)
loss tf.Tensor(0.0, shape=(), dtype=float32)

Not able to get the right result for loss. I checked my code and canā€™t find the problem.
my code for loss was ā€™ loss = tf.maximum(tf.reduce_sum(basic_loss), 0) ā€™

I think you have the computation ā€œinside outā€. You are taking the max of the sum with zero. What they are asking for is the sum of the maxes, right? Please have another careful look at the instructions and see if what I said there makes things clearer.

Also note that this same error was discussed earlier on this thread, so it might also be worth checking some of the earlier discussions.

oh my bad, I didnā€™t think of this well
thanks