Error in Initializing Adam Optimization Method in Week 2 of Course 2

Hi I got an error while updating parameters with Adam.

The following are the codes to the error.
{assignment code removed by mentor}

Hello @ankita_dhawan,

This indicates that we are expecting for 5 values to unpack to parameters, v, s, vc, sc respectively. However, as the error message says, it only receives 3 values to unpack and so it is not sufficient.

The update_parameters_with_adam function is supposed to return 5 values which is

return parameters, v, s, v_corrected, s_corrected

This is a line of code that is outside of the exercise, so it is not supposed to be changed, so please change it back.


PS: I am removing the assignment code from your post since we can’t share it here.

Thanks your suggestion worked :slight_smile:

Hi I have a similar doubt in Course 1, Week 4 Assignment; Image Classification for detecting a cat.
Here is the error i am getting in the pre-written code.

In the code above this , I passed only Parameters. But when i also passed parameters and Cost, it showed the error as "
IndexError: too many indices for array"

Hello @ankita_dhawan,

The two_layer_model is supposed to return this:

return parameters, costs

Please change it back, and if there is another error afterwards, I need to see it’s error traceback.


As Raymond points out, the “return” logic in both of those cases was given to you in the template code and should not need to be modified. The other possibility for how this error happened is that you copied a solution from someplace and it is old. They made some pretty big changes to the course in April 2021 and you can just copy solutions from before that: it doesn’t work. It’s also against the rules to submit work that is not your own, so it really doesn’t get you anywhere in both senses (you don’t learn anything and it doesn’t even work to get you the grade if that’s all you care about). :nerd_face:

NameError Traceback (most recent call last)
----> 1 parameters, grads, learning_rate = update_parameters_with_gd_test_case()
2 learning_rate = 0.01
3 parameters = update_parameters_with_gd(parameters, grads, learning_rate)
5 print(“W1 =\n” + str(parameters[“W1”]))

NameError: name ‘update_parameters_with_gd_test_case’ is not defined
rectify this error

You can rectify it for yourself: just run the earlier cells in the notebook by doing “Cell → Run All Above”. You need to do this anytime you close and reopen the notebook or restart the kernel.

already run the earlier cell but all in vain

If you’re sure that doing:

Kernel → Restart and Clear Output
Cell → Run All Above
Then run your test cell

doesn’t work, then you must have damaged something in either the notebook or the file. Did you modify the “Import” block that is the first code cell in the notebook or did you edit You can get clean copies of both the notebook and the tests by using the procedures on this thread. Then “copy/paste” over your solution code to the clean copy and see if that helps. Note that you need to delete the file as part of the procedure or it won’t be replaced.

Also note that if you’re running the notebook locally, you need to bring over all the files associated with the notebook, not just the notebook. There’s a topic about how to do that on the DLS FAQ Thread, but note that running locally is not a simple matter and there are no “official” instructions for how to do that.

done with that… thanks