Week 1 Assignment 1 pool_forward stride of 2 failing

2 hidden tests are failing in my assignment. I suspect the issue is with my pool_forward code with a stride of 2. I have actually taken the stride into account while looping over both the vertical and horizontal axes of the output volume, and have passed all the test cases for conv_forward even with a stride of 2.
In the case where pool_forward has a stride of 2, I get the following output:
mode = max
A.shape = (2, 2, 2, 3)
A[0] =
[[[1.74481176 0.90159072 1.65980218]
[0. 0. 0. ]]

[[0. 0. 0. ]
[0. 0. 0. ]]]

mode = average
A.shape = (2, 2, 2, 3)
A[1] =
[[[-0.17313416 0.32377198 -0.34317572]
[ 0. 0. 0. ]]

[[ 0. 0. 0. ]
[ 0. 0. 0. ]]].
I am not sure why only the first row is populating with non-zero values, but the values that are showing up match the expected values.

Tip:
Do not use stride as a parameter in a range() iterator. That will skip over half of the input values you need to run the loop for.

Right! The way to think about this is that all the loops in both conv_forward and pool_forward are over the output space. You must touch every point in the output space and not skip any. The stride happens in the input space.

Just because you passed the tests for conv_forward doesn’t mean anything. The test cases for stride > 1 there are broken. I’ll bet you made the same mistake there also if you are failing two hidden tests.

1 Like

Thank you! That was the problem!

Thank you for the explanation! I would have definitely wondered why the range iterator approach was incorrect without it.