Hi,
I wonder how the “same” padding works in the tfl.MaxPooling2D() function. The model summary table shows the input “A1” is in the shape of (None, 64, 64, 8) and the output “P1” is (None, 8, 8, 8). I’m expecting the output shape to be the same as the input with padding = “same”. I also tried setting padding = “valid” in the function and got the same output dimension (None, 8, 8, 8), which made me confused about the padding argument in the tfl.MaxPooling2D() function. Could anyone explain how the padding works in the MaxPadding function? Thank you!
Hey @Xinyu_Tang,
Do you mean when you used padding = ‘same’ and ‘valid’ you got the same result ?
The whole point of a pooling layer is to reduce the h and w dimensions, so “same” padding would be sort of self-defeating. The other thing to realize is that the meaning of “Same” padding in general is not what you would naively expect: you only actually get the same output size in the case that stride = 1
and Pooling layers typically have stride > 1
. For greater strides, even with a Conv layer (as opposed to a Pooling layer), you don’t get the same output size with “Same” padding. Here’s a thread which talks about that in a bit more detail.
The output from conv_model.summary() is the same with padding = ‘same’ and ‘valid’. But padding=‘valid’ didn’t pass the following test.
Thank you for the explanation and the related thread! It makes much more sense to me. In the lecture, Andrew Ng mentioned it’s very rare to use padding in the pooling layer. Just curious what’s the reason to use padding = ‘same’ here?
Okay check @paulinpaloalto’s answer it gonna help you!
But some of the tests do essentially a “string compare” with model.output
, so it matters how you specify the parameters, even if the difference is actually not significant in terms of the computed results. Check what that comparator
function does.