Weak 3 Programming assignment using Tensorflow

I am facing a problem with computing the total loss using tf.reduce_sum & tf.keras.losses.categorical_crossentropy using (logits & labels) of the Weak 3 programming assignment. Every time on running the code I get nan as a test value.

Please someone help.

1 Like

Hello @Shankar_Kumar1, welcome to our community!

We appreciate your post, but it is in the incorrect category. To ensure that your question receives a prompt and accurate response, I suggest that you edit your post by clicking the pencil icon located next to the title and move it to the relevant course category. Our mentors will be happy to assist you.


I’m guessing this is the Introduction to TensorFlow assignment in DLS C2 W3. My guess is that you have reversed the role of the labels and logits when you call the loss function. If you pass 0 or 1 exactly as a logit and also have the from_logits flag set incorrectly then you end up with NaN.

If you have trouble moving the thread by the method that Saif described, just let us know if I have the right theory about where it belongs and I can move it for you.

1 Like

Here’s a thread which discusses the point about the prediction outputs being “logits” instead of activation values.

Here’s another thread which lists the most common mistakes on that function.

1 Like