Problem in "Convolution_model_Step_by_Step_v1 >>> pool_forward() >>># Case 2: stride of 2"

Hi all

In “Convolution_model_Step_by_Step_v1 >>> pool_forward() >>># Case 1: stride of 1

I get the RIGHT values

But in In “Convolution_model_Step_by_Step_v1 >>> pool_forward() >>># Case 2: stride of 2

I get the WRONG values

What could I try in order to fix it?

My output is:

mode = max
A.shape = (2, 2, 2, 3)
A[0] =
 [[[1.74481176 0.90159072 1.65980218]
  [1.74481176 1.46210794 1.65980218]]

 [[1.14472371 0.90159072 2.10025514]
  [1.14472371 0.90159072 1.65980218]]]

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

 [[ 0.44497696 -0.00261695 -0.31040307]
  [ 0.50811474 -0.23493734 -0.23961183]]]

The expected output is:

Expected Output:

mode = max
A.shape = (2, 2, 2, 3)
A[0] =
 [[[1.74481176 0.90159072 1.65980218]
  [1.74481176 1.6924546  1.65980218]]

 [[1.13162939 1.51981682 2.18557541]
  [1.13162939 1.6924546  2.18557541]]]

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

 [[ 0.42944926  0.08446996 -0.27290905]
  [ 0.15077452  0.28911175  0.00123239]]]

Notice how the first row for both A[0] and A[1] is correct, but all subsequent rows are not.

P.S: Is there any other specific info I could give you in order to help me fix this?

I’ve been trying various things over the past 2 hours and got nowhere, could it be that the ‘Expected output’ given is wrong by any chance?

That most likely means that you are handling the stride incorrectly. Unfortunately the tests cases in the notebook for conv_forward do not catch it if you simply ignore the stride. In the pool_forward case, you do get wrong values but the test does not “throw”.

The logic in both cases should be the same. The loops here are over the output space and you touch every position and not skip any. The stride happens in the input space, so you need to take that into account to determine the h and w position in the input space at each iteration of the loops.

2 Likes