Testing of "conv_backward" in week 1 assignment 1

I’m trying to solve this issue for like hours.

{moderator edit - solution code removed}

it gives me the right results

dA_mean = 1.457943469708148
dW_mean = 1.7519334429380524
db_mean = 7.882856704391539

but it gave me this error and I can’t find why

---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-66-3575597a0654> in <module>
     21 assert dA.shape == (10, 4, 4, 3), f"Wrong shape for dA  {dA.shape} != (10, 4, 4, 3)"
     22 assert dW.shape == (2, 2, 3, 8), f"Wrong shape for dW {dW.shape} != (2, 2, 3, 8)"
---> 23 assert db.shape == (1, 1, 1, 8), f"Wrong shape for db {db.shape} != (1, 1, 1, 8)"
     24 assert np.isclose(np.mean(dA), 1.4524377), "Wrong values for dA"
     25 assert np.isclose(np.mean(dW), 1.7269914), "Wrong values for dW"

AssertionError: Wrong shape for db (2, 2, 3, 8) != (1, 1, 1, 8)

Wrong shape for db.
db’s shape should be initialized as b.shape, np.zeros(b.shape), instead of using W shape.

Also the above line looks suspect. Python is a case sensitive language, right?

And why use np.random.randn to initialize the variables? I guess it does no harm, since you’re going to overwrite the values, but it’s also a waste of compute. np.zeros would make more sense.


Why dA mean value gives wrong ans?

My guess is that it is because your dA values are wrong. Seems like the operative theory :nerd_face:

My “mean” values agree with the ones they show. Let’s print some of the contents of dA and see the correct values:

print(dA[0,0,:,:])
[[  0.41601058 -12.12787317  -8.33770594]
 [ -6.90397663  -1.56843937 -17.60125782]
 [ 15.84199049   3.11023817  12.90284339]
 [  3.01845418  20.73395875  -6.09838706]]
print(dA[1,3,:,:])
[[  0.19156246   9.19938463  -2.33883242]
 [ 18.18424878  11.89353277   2.22553913]
 [  9.57071875  -2.16532197 -11.8747392 ]
 [  4.05685555  11.95389449  -2.00952336]]

What do you see when you try that?

Note that they give you a lot of the moving parts of the computation here in the instructions. The math formulas can be a little hard to follow, but compare those and the rest of the instructions to what your code does.

Also note that way the stride interacts with vert_start and horiz_start is exactly the same here as it was in conv_forward. If you passed the tests for that function, make sure you used the same logic here.