DLC1W4 Programming Assignment3-: Building your Deep Neural Network: Step by Step

How to resolve this error?
We can’t access “relu_backward()” function.

~/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: boolean index did not match indexed array along dimension 0; dimension is 1 but corresponding boolean dimension is 3

You can examine the source for relu_backward by using “inspect” or you can click “File → Open” and have a look around (there’s a topic about that on the FAQ Thread). But the top level point is that just because the error gets thrown in relu_backward, that does not mean that’s where the bug is. What that means is that your code passed incorrect parameters down to relu_backward with dimensions that do not match. Now you need to figure out why. Print the shapes of the objects at the call site. Are they what you would expect from the “dimensional analysis”? At what layer does the error get thrown? What are the shapes of Z and dA at that layer? What are your shapes?

Actually we can see the bug in the code shown in the exception trace. You are in the for loop over the hidden layers, so what value of dA should you be passing in that case?

1 Like

Thanks you very much. Issue resolved. I did a mistake in “L_model_backward” function.