Explain the terms “Valid Padding” and “Same Padding” in CNN

Valid Padding: This type is used when there is no requirement for Padding. The output matrix after convolution will have the dimension of (n – f + 1) X (n – f + 1).

Same Padding: Here, we added the Padding elements all around the output matrix. After this type of padding, we will get the dimensions of the input matrix the same as that of the convolved matrix.

CNN questions padding

After Same padding, if we apply a filter of dimension f x f to (n+2p) x (n+2p) input matrix, then we will get output matrix dimension (n+2p-f+1) x (n+2p-f+1). As we know that after applying Padding we will get the same dimension as the original input dimension (n x n). Hence we have,

(n+2p-f+1)x(n+2p-f+1) equivalent to nxn

n+2p-f+1 = n

p = (f-1)/2

So, by using Padding in this way we don’t lose a lot of information and the image also does not shrink.