Practice Lab:Neural network and deep learning: step by step
Exercise 9 - L_model_backward
The problem after running is: NameError Traceback (most recent call last)
in
----> 1 t_AL, t_Y_assess, t_caches = L_model_backward_test_case()
2 grads = L_model_backward(t_AL, t_Y_assess, t_caches)
3
4 print("dA0 = " + str(grads[‘dA0’]))
5 print("dA1 = " + str(grads[‘dA1’]))
NameError: name ‘L_model_backward_test_case’ is not defined
My code as below:
Moderator Edit: Solution Code Removed.
The next excersise happens the same NameError:
Exercise 10 - update_parameters
NameError Traceback (most recent call last)
in
----> 1 t_parameters, grads = update_parameters_test_case()
2 t_parameters = update_parameters(t_parameters, grads, 0.1)
3
4 print ("W1 = "+ str(t_parameters[“W1”]))
5 print ("b1 = "+ str(t_parameters[“b1”]))
NameError: name ‘update_parameters_test_case’ is not defined
My code as below:
Moderator Edit: Solution Code Removed.
First, sharing your code is not allowed. So, avoid sharing it.
Second, you have to pass all the previous exercises before moving to the next one as the next exercise depends on the previous one.
Lastly, you have to run all the cells from the top every time you open your assignment. Your error shows that you didn’t run the above cells.
Once you do this, you will get other errors as your code is also incorrect. Please share that error (not code) with us.
2 Likes
Thank you for the reminder.
After run the previous code I got an indeError: tuple Index out of range
IndexError Traceback (most recent call last)
<ipython-input-27-3ace16762626> in <module>
1 t_AL, t_Y_assess, t_caches = L_model_backward_test_case()
----> 2 grads = L_model_backward(t_AL, t_Y_assess, t_caches)
3
4 print("dA0 = " + str(grads['dA0']))
5 print("dA1 = " + str(grads['dA1']))
<ipython-input-26-b2f08748e366> in L_model_backward(AL, Y, caches)
39 # grads["db" + str(L)] = ...
40 # YOUR CODE STARTS HERE
---> 41 current_cache = caches[L]
42
43 grads["dA" + str(L-1)], grads["dW" + str(L)], grads["db" + str(L)] = linear_activation_backward(dAL, current_cache, activation = "sigmoid")
IndexError: tuple index out of range
Your current_cache
for sigmoid
is incorrect. Check the below line from the notebook:
caches -- list of caches containing:
every cache of linear_activation_forward() with "relu" (it's caches[l], for l in range(L-1) i.e l = 0...L-2)
the cache of linear_activation_forward() with "sigmoid" (it's caches[L-1])
Thank you for your notebook.
It looks sigmoid has not problem, but it turns relu as below now:
IndexError Traceback (most recent call last)
<ipython-input-26-3ace16762626> in <module>
1 t_AL, t_Y_assess, t_caches = L_model_backward_test_case()
----> 2 grads = L_model_backward(t_AL, t_Y_assess, t_caches)
3
4 print("dA0 = " + str(grads['dA0']))
5 print("dA1 = " + str(grads['dA1']))
<ipython-input-25-50b2421477cc> in L_model_backward(AL, Y, caches)
61 dA_prev_temp, dW_temp, db_temp = linear_activation_backward("dA" + str(l + 1),
62 current_cache,
---> 63 activation = "relu")
64 grads["dA" + str(l)] = dA_prev_temp
65 grads["dW" + str(l+1)] = dW_temp
<ipython-input-17-c2fbdb0982d3> in linear_activation_backward(dA, cache, activation)
20 if activation == "relu":
21 ### START CODE HERE ### (≈ 2 lines of code)
---> 22 dZ = relu_backward(dA, activation_cache)
23 dA_prev, dW, db = linear_backward(dZ, linear_cache)
24
~/work/release/W4A1/dnn_utils.py in relu_backward(dA, cache)
54
55 # When z <= 0, you should set dz to 0 as well.
---> 56 dZ[Z <= 0] = 0
57
58 assert (dZ.shape == Z.shape)
IndexError: too many indices for array
Make sure you have passed all the above tests. If so, send me your code of L_model_backward
function in a private message. Click my name and message.