Skip to content

Instantly share code, notes, and snippets.

@ttpro1995
Created March 3, 2020 16:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ttpro1995/f5c7b8b6722da2bb23a6a853328da6ec to your computer and use it in GitHub Desktop.
Save ttpro1995/f5c7b8b6722da2bb23a6a853328da6ec to your computer and use it in GitHub Desktop.
calculate_padding.py
def calculate_padding(kernel_size, dilation):
"""
https://discuss.pytorch.org/t/how-to-keep-the-shape-of-input-and-output-same-when-dilation-conv/14338
o = output
p = padding
k = kernel_size
s = stride
d = dilation
:return:
"""
k = kernel_size
d = dilation
p = -1 + k + (k-1)*(d-1)
p = p/2
return p
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment