Week 3 - Assignment - compute_total_loss - try to set from_logits=False
I have spended more than 2 hours for this problem, but it still show errors. help me please!
Hi, did you complete the compute total loss function?
Hi @NyashaEysenck , @zhifine ,
Just in case you have missed the instruction for this exercise, here is an extract:
Exercise 6 - compute_total_loss
Implement the total loss function below. You will use it to compute the total loss of a batch of samples. With this convenient function, you can sum the losses across many batches, and divide the sum by the total number of samples to get the cost value.
- It’s important to note that the “
y_pred
” and “y_true
” inputs of tf.keras.losses.categorical_crossentropy are expected to be of shape (number of examples, num_classes). tf.reduce_sum
does the summation over the examples.
As you can see from this instruction, you need to play attention to the input parameters as they are arranged differently from the [tf.keras.losses.categorical_crossentropy](tf.keras.losses.categorical_crossentropy | TensorFlow v2.16.1
Let’s know if you still have problem.
Make sure you’re correctly summing the loss values. The hint in the error message suggests that the issue might be related to how the loss values are aggregated.
Here is a thread with a checklist of the most common problems for that function.
Please note that the definition of this function is that it computes the sum of the costs across each minibatch, not the average. Here’s a thread which explains why it is done that way.