No gradients provided for any variable (DLS C2 W3 Assignment)

Hello,

In section 3.3 in the assignment of week 3 about model training, it is supposed to run without problems after finishing the previous sections. However, I am getting an error “No gradients provided for any variable” where “tap.gradinet” returns None values. I am not sure where the problem is.

Thanks!

1 Like

If you are using Tensorflows gradienttape you need to calculate gradients with respect to certain variables. Have a look on the official TF page on this to understand it better:

Gradient tape

Thanks for your reply!
The code is already provided in the notebook of the assignment. The gradient of the cost function is obtained wrt the weight and bias variables. However, it seems not working.
I checked that these variables are watched by the tape, and all variables are of type tensor, but no luck.

One thing that can cause that error is using numpy functions instead of TF functions. If you are calculating gradients, that only works if all the calls in the call graph are TF functions. That applies to all the functions you wrote earlier that are called by the model code, of course.

3 Likes

Thanks for your reply!

All the functions I used are TF functions. Here are sample codes:

The network

{moderator edit - solution code removed}

All exercises ran correctly, but the last part gave this problem.

Thanks anyway!

Please check your DMs for a message from me …

Just Done! Thanks a lot!

Oh, sorry, I didn’t look closely enough at the code you posted earlier. You can see it right there: you used np.transpose in the cost line. That is the problem. If you use tf.transpose, it will work.

1 Like

I see. Thanks a lot!