C4 W1 Exercise 4 - pool_forward

Hi, I have been receiving an error in the pool_forward function that I have not been able to resolve.

This is the output I am receiving:
mode = max
A.shape = (2, 3, 3, 3)
A[1, 1] =
[[1.96710175 1.96710175 1.96710175]
[1.96710175 1.96710175 1.96710175]
[1.62765075 1.62765075 1.62765075]]

mode = average
A.shape = (2, 3, 3, 3)
A[1, 1] =
[[0.04398565 0.04398565 0.04398565]
[0.01118852 0.01118852 0.01118852]
[0.0233857 0.0233857 0.0233857 ]]
Error: Wrong output in MAX-Pool for variable in position 0.
Error: Wrong output in AVG-Pool for variable in position 0.
4 Tests passed
2 Tests failed

For the max and average modes I am simply using np.max(a_prev_slice) and np.mean(a_prev_slice). I suspect that is where my error is but I’m not sure how to resolve it. Any hints would be greatly appreciated!

Using np.max and np.mean is correct, of course. So that suggests that your input values are incorrect. Note that your outputs are the same across each row in both cases, whereas the “expected values” are not the same across each row. That suggests that your code for computing the “start/end” values and how the strides work is incorrect.

Here are the correct values:

mode = max
A.shape = (2, 3, 3, 3)
A[1, 1] =
 [[1.96710175 0.84616065 1.27375593]
 [1.96710175 0.84616065 1.23616403]
 [1.62765075 1.12141771 1.2245077 ]]

mode = average
A.shape = (2, 3, 3, 3)
A[1, 1] =
 [[ 0.44497696 -0.00261695 -0.31040307]
 [ 0.50811474 -0.23493734 -0.23961183]
 [ 0.11872677  0.17255229 -0.22112197]]
 All tests passed.

Note that for the “max” case, your elements in the first column are correct, but in the “average” case they are not. That suggests that your “end” values are wrong.

1 Like

I got similar error. Look at the way you are extracting a_prev_slice. I suspect your slicing is good but r u using ( i) and (c) correctly to slice the right example and right channel? Hint: Pooling happens on one channel at a time as shown in A[i,h,w,c].
These are tricky examples :). Thanks for your help Paul.

2 Likes

Thank you Paul and Shobhit. This helped resolve my issue. I was not slicing the channel appropriately.

1 Like