C4W2 ex. 3

I tried to define the loss function as follows but there seems to be missing arguments: y_true and y_pred. However, I haven’t been able to figure out what to use there. Help, please

# Define a BinaryCrossentropy loss function. Use from_logits=True
loss_function=tf.keras.metrics.binary_crossentropy(from_logits=True)

Have a look on this page:

I did, my problem is that idk what exactly to write in place of y_true and y_pred. I understand if you can’t directly answer to this but could you give me a hint pleas?

I think the pages explains it pretty well:

Args

y_true Ground truth values. shape = [batch_size, d0, .. dN].
y_pred The predicted values. shape = [batch_size, d0, .. dN].

y_true are the labels an y_pred are the predictions.

I solved it. The problem was not in the arguments but in the syntax: I wrote tf.keras.metrics.binary_crossentropy instead of tf.python.keras.losses.BinaryCrossentropy . With that change there is no need to specify y_true and y_pred

Hint is in the notebook. It says:

# Define a BinaryCrossentropy loss function. Use from_logits=True
loss_function=None

But you are using metrics.

Update: I am glad you solve it on your own.

1 Like