C4W1A1 conv_foward -- wrong z mean

Obviously I must have done something wrong, but I could not find the error. Can somebody help me debug the error? I make sure that the a_slice_prev shape is correct, and take the stride into account.

Results:
(7, 9, 4)
(7, 9, 4)
Z’s mean =
0.5151827378782476
Z[0,2,1] =
[0. 0. 0. 0. 0. 0. 0. 0.]
cache_conv[0][1][2][3] =
[-1.1191154 1.9560789 -0.3264995 -1.34267579]
First Test: Z’s mean is incorrect. Expected: 0.5511276474566768
Your output: 0.5151827378782476 . Make sure you include stride in your calculation

First Test: Z[0,2,1] is incorrect. Expected: [-2.17796037, 8.07171329, -0.5772704, 3.36286738, 4.48113645, -2.89198428, 10.99288867, 3.03171932]
Your output: [0. 0. 0. 0. 0. 0. 0. 0.] Make sure you include stride in your calculation

(11, 13, 4)
(11, 13, 4)
(5, 7, 4)
(5, 7, 4)
(17, 19, 4)
(17, 19, 4)

AssertionError Traceback (most recent call last)
in
15
16 conv_forward_test_1(z_mean, z_0_2_1, cache_0_1_2_3)
—> 17 conv_forward_test_2(conv_forward)

~/work/release/W1A1/public_tests.py in conv_forward_test_2(target)
117 [-0.47552486, -0.16577702, -0.64971742, 1.63138295]])
118
→ 119 assert np.isclose(Z_means, expected_Z), f"Wrong Z mean. Expected: {expected_Z} got: {Z_means}"
120 assert np.allclose(cache_conv[0][1, 2], expected_conv), f"Values in Z are wrong"
121

AssertionError: Wrong Z mean. Expected: -0.5384027772160062 got: -0.2981759579224176

I am not sure if sharing a code is allowed or not. If not allowed, I will delete the code.

It’s against the rules to share code publicly. I’m not sure that you “copy/pasted” it correctly, but it looks like the indentation is wrong. The loop over h is not nested within the loop over i the way you show the code. Indentation is a key part of the syntax in python.

1 Like

Thank you! the indentation was the source of the error.

It’s good news that solved the problem. Thanks for removing the code. It did certainly help to see it in that case and no harm is really done as long as we don’t leave it sitting there for others to copy.