Week 1 Assignment 1 Exercise 8

I’m struggling with the pool_backward function. I’m getting the correct mean values, but my dA_prev[1, 1]s are off a bit. I can’t figure out where I’m going wrong. Any help is appreciated. Here’s my code (I assume it’s ok to share it since the exercise is ungraded):

{moderator edit - solution code removed}

And here the results:
(5, 4, 2, 2)
(5, 5, 3, 2)
mode = max
mean of dA = 0.14571390272918056
dA_prev1[1,1] = [[ 0. 0. ]
[10.11330283 -0.49726956]
[ 0. 0. ]]

mode = average
mean of dA = 0.14571390272918056
dA_prev2[1,1] = [[-0.32345834 0.45074345]
[ 2.52832571 -0.24863478]
[ 1.26416285 -0.12431739]]

Hi @Shera ,

Your error is in the selection from dA. Right now you are selecting:

dA[i, vert_start:vert_end, horiz_start:horiz_end, c]

Can you think of a more appropriate selection?

Let me know how it goes.


You may also want to check this post out with the exact same issue:

Right! The point is that the way the loops work here is exactly analogous to how they work in forward propagation: the loops are over the output space and there is just one entry in the output space at every position. But that is mapped from (in the forward case) or to (in the backward case) a filter patch area in the input space.

That worked! thanks a lot :slight_smile:

Great! I am happy that you were able to solve this issue.

Move on to the next lessons!


Thanks for the hint, it helped :slight_smile:

Deleting the code, so that others may enjoy completing the work for themselves.