In the second part of the assignment where the Functional API is used, why do we apply “same” padding for the pooling layers? The lecture mentions that padding for pooling layers is rarely used; it is typically set to zero or ‘valid’. In fact, TensorFlow’s default value is ‘valid’. What is the rationale behind using ‘same’ padding in this context? I apologize if I misunderstood something in the lecture or in the assignment.
“Same” padding ensures that the output feature map has the same spatial dimensions (height and width) as the input feature map. This might be required in the model design if you don’t want to reduce the image (mapping) further. check what the model is doing in your case!
For this particular model architecture / problem, padding='same'
produces better results than with padding='valid'
when tested over multiple runs. Odds are good that the staff tried different hyperparameters and settled on this one. Adding @Mubsi to add any missing details.
One important thing to note is that “same” padding only produces the same output size if the stride is 1. If the stride is greater than 1, then the size will not be the same. But in most cases is it still different than the size would be with valid padding. In most cases pooling layers do not have a stride of 1.
Here’s a thread which shows some examples of how this works and here’s one that explains why same is not necessarily the same.
In this model, both “same” and “valid” produce the same output dimension. Why would one option be better than the other?
Thanks for bringing this up. I was wrong. padding='same'
isn’t required for the pooling layers with this configuration.
Upon enabling op determinism & setting the seed, the results were identical in both cases.
tf.keras.utils.set_random_seed(1)
tf.config.experimental.enable_op_determinism()
This is how output shape is calculated when padding = ‘same’ / ‘valid’ for a pooling layer.