Week 4-Face Recognition

For Exercise 1 when I try to run the unit test I get
in
26 y_pred_perfect = ([[1., 0.], [1., 0.]],[[1., 0.], [1., 0.]], [[0., 1.], [0., 1.]])
27 loss = triplet_loss(y_true, y_pred_perfect, 3)
—> 28 assert loss == 2., “Wrong value. Are you applying tf.reduce_sum to get the loss?”
29 y_pred_perfect = ([[1., 1.], [2., 0.]], [[0., 3.], [1., 1.]], [[1., 0.], [0., 1.,]])
30 loss = triplet_loss(y_true, y_pred_perfect, 1)

/opt/conda/lib/python3.7/site-packages/tensorflow/python/framework/ops.py in bool(self)
982
983 def bool(self):
→ 984 return bool(self._numpy())
985
986 nonzero = bool

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

I am positive that I did not change the code cell chunk.
This is the unit cell given to me.

YOU CANNOT EDIT THIS CELL

BEGIN UNIT TEST

tf.random.set_seed(1)
y_true = (None, None, None) # It is not used
y_pred = (tf.keras.backend.random_normal([3, 128], mean=6, stddev=0.1, seed = 1),
tf.keras.backend.random_normal([3, 128], mean=1, stddev=1, seed = 1),
tf.keras.backend.random_normal([3, 128], mean=3, stddev=4, seed = 1))
loss = triplet_loss(y_true, y_pred)

assert type(loss) == tf.python.framework.ops.EagerTensor, “Use tensorflow functions”
print("loss = " + str(loss))

y_pred_perfect = ([[1., 1.]], [[1., 1.]], [[1., 1.,]])
loss = triplet_loss(y_true, y_pred_perfect, 5)
assert loss == 5, “Wrong value. Did you add the alpha to basic_loss?”
y_pred_perfect = ([[1., 1.]],[[1., 1.]], [[0., 0.,]])
loss = triplet_loss(y_true, y_pred_perfect, 3)
assert loss == 1., “Wrong value. Check that pos_dist = 0 and neg_dist = 2 in this example”
y_pred_perfect = ([[1., 1.]],[[0., 0.]], [[1., 1.,]])
loss = triplet_loss(y_true, y_pred_perfect, 0)
assert loss == 2., “Wrong value. Check that pos_dist = 2 and neg_dist = 0 in this example”
y_pred_perfect = ([[0., 0.]],[[0., 0.]], [[0., 0.,]])
loss = triplet_loss(y_true, y_pred_perfect, -2)
assert loss == 0, “Wrong value. Are you taking the maximum between basic_loss and 0?”
y_pred_perfect = ([[1., 0.], [1., 0.]],[[1., 0.], [1., 0.]], [[0., 1.], [0., 1.]])
loss = triplet_loss(y_true, y_pred_perfect, 3)
assert loss == 2., “Wrong value. Are you applying tf.reduce_sum to get the loss?”
y_pred_perfect = ([[1., 1.], [2., 0.]], [[0., 3.], [1., 1.]], [[1., 0.], [0., 1.,]])
loss = triplet_loss(y_true, y_pred_perfect, 1)
if (loss == 4.):
raise Exception(‘Perhaps you are not using axis=-1 in reduce_sum?’)
assert loss == 5, “Wrong value. Check your implementation”

END UNIT TEST

any help would be awesome :slight_smile:

That cell is used to test your code.
The error is not in the test, it is in your code. It does not pass the tests.

Thanks, realized I forgot to sum at the end