W3 | Planar Data Classification | Backprop wrong values

Hi there!

I’m on the Planar Data Classification assignment, Exercise 6 (Backward Propagation). db2 and dW2 are correct.

The values for dW1 are incorrect. I’ve pored over the formulae in the notes for ages and can’t see where I’ve gone wrong…


AssertionError Traceback (most recent call last)
in
7 print ("db2 = "+ str(grads[“db2”]))
8
----> 9 backward_propagation_test(backward_propagation)

~/work/release/W3A1/public_tests.py in backward_propagation_test(target)
187 assert output[“db2”].shape == expected_output[“db2”].shape, f"Wrong shape for db2."
188
→ 189 assert np.allclose(output[“dW1”], expected_output[“dW1”]), “Wrong values for dW1”
190 assert np.allclose(output[“db1”], expected_output[“db1”]), “Wrong values for db1”
191 assert np.allclose(output[“dW2”], expected_output[“dW2”]), “Wrong values for dW2”

AssertionError: Wrong values for dW1

Hi, Brendon.

Did you mention the codes correctly, using the parameters as per the formula?

There are two tests in here.

The first test is to use smaller size of X and Y to check the basic function with print out, and the 2nd test is to use slightly large size of X and Y to check output types, shapes and values of all variables with assertions.

In this sense, “dW1” is the first variable to check the value in the 2nd test. At this time, we can not say all others are correct since those are not tested yet.

And, the first test is just “print out” variables. Even if the value is same as an expected values, this is just one aspect. This does not cover all combinations of parameters. So, we need to see full results of the 2nd test.

So, the first step to do is, please post the output from the first test. We can see your outputs, ‘dW1’, ‘db’1’,‘dW2’ and 'db2", and understand differences from the expected values.

Let’s do one by one.

Thanks so much - here is the full output. I have added a number of print statements as well:

parameters, cache, t_X, t_Y = backward_propagation_test_case()

grads = backward_propagation(parameters, cache, t_X, t_Y)
print ("dW1 = "+ str(grads[“dW1”]))
print ("db1 = "+ str(grads[“db1”]))
print ("dW2 = "+ str(grads[“dW2”]))
print ("db2 = "+ str(grads[“db2”]))

backward_propagation_test(backward_propagation)

dZ1 is: [[-3.26004476e-05 -1.09075671e-05 1.84851426e-05]
[-2.37374037e-04 -1.23847186e-04 -1.20215524e-04]
[ 5.53878665e-05 1.01628980e-05 -7.94748317e-05]
[-2.46605107e-04 -1.58717233e-04 -2.97831053e-04]]

dW1 is: [[-1.86816473e-05 -5.66816846e-06]
[-8.21062208e-05 1.41399092e-04]
[ 4.19093891e-05 4.40933358e-05]
[-4.87232092e-05 2.70904710e-04]]

db1 is: [[-8.34095739e-06]
[-1.60478916e-04]
[-4.64135575e-06]
[-2.34384464e-04]]

dW1 = [[-1.86816473e-05 -5.66816846e-06]
[-8.21062208e-05 1.41399092e-04]
[ 4.19093891e-05 4.40933358e-05]
[-4.87232092e-05 2.70904710e-04]]
db1 = [[-8.34095739e-06]
[-1.60478916e-04]
[-4.64135575e-06]
[-2.34384464e-04]]
dW2 = [[ 0.00078841 0.01765429 -0.00084166 -0.01022527]]
db2 = [[-0.16655712]]
dZ1 is: [[-0.18971001 0.09749821 -0.09071685 -1.05286106 -0.7742922 1.0076847
-0.4663882 ]
[ 0.28017893 -0.2952923 -0.10045365 -0.31272244 1.02460768 0.31600204
0.38243472]
[-0.14182549 -1.56040309 0.02828891 0.22074501 -0.10490566 -0.46963613
0.10164975]
[-0.02249924 0.42123163 -0.01473512 -0.04108494 -0.19480444 -0.42116668
0.0291115 ]
[ 0.21989938 1.24339264 -0.05122532 -0.08084212 0.1838087 -0.04746717
-0.30212852]
[ 0.34859902 -0.74184141 0.12623696 0.35946419 0.27043228 -1.01602709
-0.07034865]
[-0.61420572 2.62781985 0.04557935 -0.04825444 1.03894577 -0.48569235
0.58364007]
[ 0.29185168 -0.39544046 0.09198354 0.023439 0.50051602 -0.70754
0.11546824]
[-0.00485776 -0.50818514 0.05188744 0.69246679 -0.33448209 0.45326614
-0.26711585]]

dW1 is: [[-0.42760887 0.0154449 0.24078632]
[ 0.26443449 -0.44275199 0.10582902]
[ 0.23426834 0.03633253 0.13811406]
[ 0.08702401 0.08872219 -0.10513384]
[-0.07835778 -0.01763681 -0.10369397]
[ 0.43105965 -0.03006614 0.0529339 ]
[ 0.06538961 -0.14056184 -0.63339413]
[ 0.41504288 -0.16919208 0.03015348]
[-0.32373508 0.2123736 0.06866423]]

db1 is: [[-0.20982649]
[ 0.184965 ]
[-0.27515524]
[-0.03484961]
[ 0.16649108]
[-0.10335496]
[ 0.44969036]
[-0.01138885]
[ 0.01185422]]


AssertionError Traceback (most recent call last)
in
7 print ("db2 = "+ str(grads[“db2”]))
8
----> 9 backward_propagation_test(backward_propagation)

~/work/release/W3A1/public_tests.py in backward_propagation_test(target)
187 assert output[“db2”].shape == expected_output[“db2”].shape, f"Wrong shape for db2."
188
→ 189 assert np.allclose(output[“dW1”], expected_output[“dW1”]), “Wrong values for dW1”
190 assert np.allclose(output[“db1”], expected_output[“db1”]), “Wrong values for db1”
191 assert np.allclose(output[“dW2”], expected_output[“dW2”]), “Wrong values for dW2”

AssertionError: Wrong values for dW1

With a quick look, both dW1 and db1 are not correct since dZ1 is not correct. dW2/db2 seems to be OK.
To obtain dZ1, you need to be careful about the difference between np.dot and np.multiply (or simply *). Andrew uses * for element-wise operation (Hadamard product) and nothing for dot product. Please see the equation carefully, and double check your implementation. For {g^{[1]}}^{'}(Z^{[1]}), please refer Tips in the notebook.

1 Like