Types of padding
- Valid Padding
- same Padding
What is the difference between ‘SAME’ and ‘VALID’ padding in tf.nn.max_pool of tensorflow?
Padding is a technique used in convolutional neural networks (CNNs) to preserve the spatial dimensions of the input data and prevent the loss of information at the edges of the image. It involves adding additional rows and columns of pixels around the edges of the input data. There are several different ways to apply padding in Python, depending on the type of padding being used.
Let’s an image of dimension is having filtered with dimension kernel with stride then the output shape will be:
Then the output shape will be
Where, C = number of filtered channel.
For example the image of shape is filtered with kernel with stride length =2 then the output shape of the image will be.
So, the image shrinks when the convolution is performed.
And the corner and edge pixels do have not equal participation. as we can see from the figure below.
To resolve this we add extra layers of zeros to our image, which is known as the same padding.