How to keep the shape of input and output same when dilation conv?

You could visualize it with some tools like ezyang’s convolution visualizer or calculate it with this formula:

  • o = output
  • p = padding
  • k = kernel_size
  • s = stride
  • d = dilation
o = [i + 2*p - k - (k-1)*(d-1)]/s + 1

In your case this gives o = [32 + 2 - 3 - 2*1]/1 +1 = [29] + 1 = 30.
Now, you could set all your parameters and “solve” the equation for p.
You will see, that p=2 will give you an output size of 32.

44 Likes