Week 3 Exercise 6 mean error?

I cannot compute cost. I get:

AssertionError: Test does not match. Did you get the mean of your cost functions?

But is only a line of code and i checked that line as much as i can. I am getting the mean (tf.reduce_mean())

What could be going on? I am not expert at python.

i shoul mutuply by (-1/m)?
m is num examples in logits?


Fixed by @z009LL.

A few hints for others with the same problem:

  • reduce_mean, as its name suggests, already computes the mean.
  • y_pred and y_true should have shape (number of examples, num_classes) .
  • Make sure you’re passing the right parameters to categorical_crossentropy.
  • [Update] There is no need to set label_smoothing, which is a regularization parameter.

Good luck with the rest of the specialization :slight_smile:


Same error message here. I have tried to transpose the inputs to match with the format, applied softmax to logits, but I’m still not getting the correct number. I’m not seeing where else can the error come from. Anything I missed?


Fixed by @Maggie too.

Do not try to call tf.keras.activations.softmax explicitly. Instead, see if categorical_crossentropy has a parameter that can help you.

Good luck with the rest of the assignment :slight_smile:


Definitivamente no encuentro solución para este problema con las pistas que da. Puede exponer otras?

The problem with my answer was that I used reshape to conduct tensor transpose.

1 Like