Same padding when kernel size is even

3.7k views Asked by At

When the kernel size is odd, we can manually calculate the necessary padding to get the output in the same dimension as input such that it creates same padding.

But how can we calculate padding dimensions for kernels with even sizes (ex: (2x2)?

2

There are 2 answers

0
Bimsara Gayanga On BEST ANSWER

enter image description here

I used padding as 1 and dilation as 2 which resulted same padding.

0
Prajot Kuvalekar On

note these the 2 formula's

  1. pad= (filter_size - 1 )/ 2
  2. o/p feature map dimension= (i/p feature map dimension - filter_size + 2(pad))/stride + 1

lets assume u have i/p dimension of 28x28, and you want same padding implies your o/p dimension to be same i.e 28x28. and i am assuming your stride as 1

let us come to calculation of padding amount, pad = (2 - 1) / 2 = 1 / 2 substituting this value to equation 2)

o/p feature map=(28 - 2 + 2(1/2))/1 + 1 =28

Hence the last answer is your dimension of your o/p feature map,(hence verified)