GRADED FUNCTION: compute_cost
@tf.function
def compute_cost(logits, labels):
"""
Computes the cost
Arguments:
logits -- output of forward propagation (output of the last LINEAR unit), of shape (6, number of examples)
labels -- "true" labels vector, same shape as Z3
Returns:
cost - Tensor of the cost function
"""
## YOUR CODE STARTS HERE(1 line of code)
cost = tf.reduce_mean(tf.keras.losses.binary_crossentropy(y_true = labels, y_pred = logits, from_logits=True))
# YOUR CODE ENDS HERE
return cost
Output
NameError Traceback (most recent call last)
in
1 # GRADED FUNCTION: compute_cost
----> 2 @tf.function
3 def compute_cost(logits, labels):
4
5 “”"
NameError: name ‘tf’ is not defined
I am getting this error.