Convolution_model_Application - MaxPooling Padding Question

When we are creating the convolutional_model in Exercise 2, the MaxPooling2D layer is created with padding = ‘same’. However, when reviewing the summary of the model, we see that after the MaxPooling layer, we still end up with a smaller output matrix (2x2x16) instead of (8x8x16).

When i change the padding to ‘valid’, I still end up seeing the same model summary (outputs 2x2x16). Does anyone know why setting the padding = ‘same’ doesn’t change the output matrix to be the same size as the input matrix for that layer?

“valid” and “same” don’t do exactly what you’d expect from the names.

1 Like

Understood, so “valid” and “same” have a different behavior when it comes to max-pooling as opposed to the way it functions in the Convolution layers.

The way I understand it, with “valid” you’re dropping of some information from the input matrix (depending on the size of the kernel), vs. with “same” the input matrix is padded with enough 0s to utilize all the information within the input matrix.

Thanks!

Well, it’s not that it works differently in the max-pooling case. It’s the fact that it works differently when stride != 1. “Same” padding computes the padding to give the same output size if and only if stride = 1. If the stride > 1, then you do not end up with the same output size.

Here’s a thread which discusses this point in more detail. Note that it also applies to transposed convolutions as well as shown on this thread (read from the linked post to the end of the thread). The second thread gives concrete examples of the padding results when stride > 1.