Week 3, Compute Cost, TF programming assignment

Hello,
I’m a little stuck on Compute Cost part of the programming assignment. Here’s my one of code that I wrote:
cost = tf.reduce_mean(tf.keras.losses.categorical_crossentropy(tf.transpose(labels),tf.transpose(logits)))

I’m getting the error that says “AssertionError: Test does not match. Did you get the mean of your cost functions?”

My output is tf.Tensor(0.8071431, shape=(), dtype=float32)
The expected output is tf.Tensor(0.4051435, shape=(), dtype=float32).

What am I doing wrong with the code here? Any help/insight would be greatly appreciated. I’ve looked at similar posts and I’m still not understanding why I’m wrong.

Thank you,
Nay

That is the value that you get if you forget to tell the loss function that you are passing it “logits” instead of the outputs of the activation function. There is a from_logits parameter and the default value is False. That is not appropriate in our case here. They don’t really mention this in the instructions, so you have to read the documentation for the loss function and then think about it. They do give you that link. Also remember that when we wrote the forward propagation logic, they told us not to apply the activation function at the output layer.

1 Like

you can see the link https://www.tensorflow.org/api_docs/python/tf/keras/metrics/categorical_crossentropythe test give
I got the same problem ,then and a parameter, and ok
{moderator edit - solution code removed}

1 Like

@jinjh2018 It’s great to hear that you found the solution! Thanks for confirming.

Thank you @jinjh2018