I am getting the proper a_prev_slices I believe, but the final A matrix has odd repeats. Here are the first few a_prev_slices and the resultant A’s:
output dims = 3 3 3
A_prev dim = (2, 5, 5, 3)
a_prev_slice = [[ 1.62434536 -1.07296862 1.74481176]
[-1.09989127 0.04221375 1.14472371]
[-0.69166075 -0.84520564 -1.11731035]]
A = 1.74481176421648
a_prev_slice = [[-0.61175641 0.86540763 -0.7612069 ]
[-0.17242821 0.58281521 0.90159072]
[-0.39675353 -0.67124613 0.2344157 ]]
A = 0.9015907205927955
a_prev_slice = [[-0.52817175 -2.3015387 0.3190391 ]
[-0.87785842 -1.10061918 0.50249434]
[-0.6871727 -0.0126646 1.65980218]]
A = 1.6598021771098705
And here is my A[1,1]:
new A shape = (2, 3, 3, 3)
mode = max
A.shape = (2, 3, 3, 3)
A[1, 1] =
[[1.96710175 0.84616065 1.23616403]
[1.96710175 0.84616065 1.23616403]
[1.96710175 0.84616065 1.23616403]]
Here is my output for that case:
CASE 1:
a_prev_slice.shape (3, 3)
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 ]]
a_prev_slice.shape (3, 3)
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]]
a_prev_slice.shape (2, 2)
a_prev_slice.shape (5, 5)
a_prev_slice.shape (2, 2)
a_prev_slice.shape (2, 2)
All tests passed!
Notice that some of your answers are right and mine also repeat the first two elements of the first two rows, but yours gets several answers that disagree with the ones I show. So the thing to examine first is how you are doing the indexing in the input space.
How do your answers look in the average pooling case?
One key thing to notice about the difference between pooling and convolution is that pooling happens “per layer” mapping input layers straight to output layers.
1 Like
Found it - stupid error of h being used in both h and w ranges! Have to be more careful and not try to move too fast.
1 Like
Yes, that’s a good “meta” lesson to remember. Programming is one of those cases in which the saying “Go slow to go fast” applies. “Saving time” by being in too much of a hurry frequently ends up not being a net savings of time. 