Week 4 L_model_backward


IndexError 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’]))

in L_model_backward(AL, Y, caches)
58 # YOUR CODE STARTS HERE
59 current_cache = caches[l]
—> 60 dA_prev_temp, dW_temp, db_temp = linear_activation_backward(grads[“dA” + str(l+1)], current_cache, “relu”)
61 grads[“dA” + str(l)] = dA_prev_temp
62 grads[“dW” + str(l + 1)] = dW_temp

in linear_activation_backward(dA, cache, activation)
22 # dA_prev, dW, db = …
23 # YOUR CODE STARTS HERE
—> 24 dZ = relu_backward(dA, activation_cache)
25 dA_prev, dW, db =linear_backward(dZ, linear_cache)
26 # YOUR CODE ENDS HERE

~/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


So, I am not really what we are doing in this part of the assignment.
I have been stuck on this and do not know what to do.

for some reason I found that the values for these are the same

# dA_prev_temp, dW_temp, db_temp = ...
# grads["dA" + str(L-1)] = ...
# grads["dW" + str(L)] = ...
# grads["db" + str(L)] = ...

Just because the error is being thrown in a routine that you didn’t write does not mean it’s not your fault: it means you passed bad (mismatching) parameters down to relu_backward. You can start by examining the code in relu_backward to understand what it is doing. Click “File → Open” and then open the appropriate utility python file. Once you see what is going on, you’ll notice that you should be passing dA and Z from the same layer, so the shapes of those two should match. But apparently they don’t. The next step would be to print the shapes at the call site of relu_backward in your code. Why are they not what you would expect?