Conv Nets Week1 : Conv_Forward Assignment error, not passing Test1

Hello,

I am having a problem with my code in conv_forward function where it is passing conv_forward_test2 but not test 1, please see the output below, somehow when i use the common part for calculating vert_start ,vert_end etc from this code in the pool_forward assignment it passes the test. Any pointers would be helpful as i have been stuck with only this function since some time now. I have pasted error below.

regards

np.random.seed(1)
A_prev = np.random.randn(2, 5, 7, 4)
W = np.random.randn(3, 3, 4, 8)
b = np.random.randn(1, 1, 1, 8)
hparameters = {“pad” : 1,
“stride”: 2}

Z, cache_conv = conv_forward(A_prev, W, b, hparameters)
z_mean = np.mean(Z)
z_0_2_1 = Z[0, 2, 1]
cache_0_1_2_3 = cache_conv[0][1][2][3]
print(“Z’s mean =\n”, z_mean)
print(“Z[0,2,1] =\n”, z_0_2_1)
print(“cache_conv[0][1][2][3] =\n”, cache_0_1_2_3)

conv_forward_test_1(z_mean, z_0_2_1, cache_0_1_2_3)
conv_forward_test_2(conv_forward)

Z’s mean =
0.02834256615145314
Z[0,2,1] =
[-0.91364906 -5.93941251 6.39191803 5.55329522 -2.32821606 2.86099341
-0.83017133 1.36532492]
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.02834256615145314

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.91364906 -5.93941251 6.39191803 5.55329522 -2.32821606 2.86099341
-0.83017133 1.36532492]

Second Test: All tests passed!

Are you sure that you really passed all the tests for pool_forward? You have to carefully examine all the values in the stride = 2 test case to detect errors: that test doesn’t “throw” if the values don’t match.

By far the most common error here is not taking the stride into account correctly. The way to think of it is that the loops here are over the output space and we must touch every position in the output space: the stride happens in the input space by affecting the vert_start and horiz_start values appropriately. Note that it the stride works the same way in pool_forward as it did in conv_forward.

2 Likes

Hi Paulin,

Thanks for the nudge in right direction! i was using wrong formulas with stride for horiz_start and vert_start, i corrected them and iam now passing the test.

regards

Thank You so much Paulin for this insight into right direction. Were stuck at the same problem, and this helped to understand the problem. Thanks