So you have to return it as a Tensor otherwise the test fails.
The reason that this matters is that if you want to train a model using TF’s automatic gradient computations, you can’t have any numpy functions in the computation graph because they don’t get the automatic gradients calculated. That point is a general one and doesn’t really apply here, since we don’t actually run any training and only use a pretrained model in this assignment. But it’s something to keep in mind in general. If you want to see an example of the type of failure intermixing numpy calls causes, go back to Course 2 Week 3 and in the compute_cost function, use logits.numpy().T to do the transpose instead of tf.transpose. It passes the unit test for the function, but when you run the training later things explode and catch fire.
According to the TensorFlow doc, that is exactly what a TensorFlow scalar looks like. See آشنایی با تنورسازان | TensorFlow Core
Specifically this section…
Here is a “scalar” or “rank-0” tensor . A scalar contains a single value, and no “axes”.
# This will be an int32 tensor by default; see "dtypes" below.
rank_0_tensor = tf.constant(4)
print(rank_0_tensor)
tf.Tensor(4, shape=(), dtype=int32)
I think this is literally true, and might be useful in some situations (eg printing or extracting just the numeric value of the 0-rank Tensor) , however @paulinpaloalto ’s experiment suggests this might not be one of those situations, since the return type is expected to be of type tf.python.framework.ops.EagerTensor
There was no error but since the exercise specified it to be in scalar , I thought maybe it will trickle down later. But since that’s the only use of the triplet_loss fn. there is no such issue.
Sorry for confusing everyone