C2 W3 Programming Assignment TensorFlow Introduction


I have a problem with the computation of the cost in the function # GRADED FUNCTION: compute_cost of the last Assignment of Improving Deep Neural Networks: Hyperparameter Tuning, Regularization and Optimization.

I was sure I had no mistake, while the expected cost is 0.810287 and my function does not pass the tests. Can you verify, please, that there are no mistakes in the verification part? Also, the explanation part according to which we have to implement the function is confusing. Can I have a discussion with the instructor to clarify? Thank you!

ValueError: Shapes (6, 2) and (1, 6, 2) are incompatible



{moderator edit - solution code removed}

1 Like

Please share your full error. Maybe reading this help.

1 Like

There is no problem in the verification code that is given to you.

You have not specified the arguments to the loss function correctly, but that is not the reason for that particular error. Please check the definition of the loss function. There is something wrong with the shape of one of the labels or logits arguments. That must mean that you did the transpose incorrectly. There should be no “reshape” operation involved. They should both have shape (2, 6) by the time the loss function is called.

Also note that new_y_train is passed as the Y argument in the test case and that value was created by the output of your previous one_hot_matrix function, so the error may be there.

Here’s another thread with a checklist of common errors on this function.

1 Like

I added some print statements to my code to show the shapes right before the call to the loss function and here’s what I see:

logits.shape (2, 6)
labels.shape (2, 6)
vector_loss [0.25361034 0.5566767 ]
total_loss = 0.8102869987
tf.Tensor(0.810287, shape=(), dtype=float32)
All test passed
1 Like

Thank you it worked really and I came to know that dimensions of the logits are the problem here.

1 Like