Conv_forward vs pooling layer

A_prev = np.random.randn(2, 5, 7, 4)
W = np.random.randn(3, 3, 4, 8)
b = np.random.randn(1, 1, 1, 8)
hparameters = {“pad” : 1,
“stride”: 2}

why this one works
a_slice_prev = a_prev_pad[vert_start:vert_end, horiz_start:horiz_end,:]
but doesn’t work
a_slice_prev = a_prev_pad[vert_start:vert_end, horiz_start:horiz_end, c]

A_prev = np.random.randn(2, 5, 5, 3)
hparameters = {“stride” : 1, “f”: 3}

why this one works
a_prev_slice = A_prev[i, vert_start:vert_end, horiz_start:horiz_end, c]
but doesn’t work
a_prev_slice = A_prev[vert_start:vert_end, horiz_start:horiz_end,:]

thank you

The conv layers handle the channels differently than the pooling layers, right? In the case of conv layers, you have the input channels and the output channels, so you need to match the input channels with your slicing for each output channel. But in the case of the pooling layers, they operate “per channel”, so you just loop over the channels one at a time.

Also note that in your second example, you need to be clear about how you are handling the “samples” dimension.

1 Like


hi dears i dont get what the issue hear

That error message means that one of the expressions you are using to index (“slice”) A_prev must not be an integer datatype. You’ll need to figure out which one by printing the types of i, vert_start and so forth. Or maybe the first step is carefully examining the code that sets all those values.