Getting error for computing "total loss" in Week 3 TensorFlow assignment

When I am calculating the total loss I used following code:

{moderator edit - solution code removed}

But I am getting below error:

1 Like

Hi @sagar_gupta16 ,

The order of the parameters passed to the tf.keras.losses.categorical_crossentropy()function is incorrect. The first parameter should be label, not logits as you have done in your code.

Hi @Kic ,
Even after changing the parameters I am getting same error:

{moderator edit - solution code removed}

1 Like

Hi @sagar_gupta16 ,

Have you rerun your code after editing? I suggest you rerun the code from the beginning.

Hi @Kic ,
I re-ran the all the blocks and getting this error:

ValueError: Shape mismatch: The shape of labels (received (12,)) should equal the shape of logits except for the last dimension (received (2, 6)).

1 Like

Hi @Kic ,
As per my understanding, when we run “one_hot_matrix_test” function the output is “[1. 0. 0. 0. 0. 0.], shape=(6,), dtype=float32” so I believe the problem is in the way we get “new_y_train” it’s shape is coming (12,) which is why the other logic is not working.

1 Like

Hi @sagar_gupta16 ,

The input arguments of the comput_total_cost() function are passed in. If you look at the cell below, you can see the code cell for testing this function, where the logits and labels are constructed. What you can do is to use a print statement at the start of the function to print out the shape of both the labels and logits to check.

2 Likes

Hi @Kic
Thanks for helping in resolving the issue.

2 Likes