EasyDeepLearn

Compute the output shape of a 2D convolution with input (H, W), kernel k, stride s, padding p, dilation d.

medium

Answer

  • Hout  =  floorH_{\mathrm{out}}\; = \;\mathrm{floor}((H + 2*p - d*(k-1) - 1) / s) + 1, same for W.
  • Special cases: 'same' padding for stride 1 uses p = (k-1)/2 * d.
  • Standard kernels are 3×3 with p=1, s=1 (preserves spatial size).
  • Downsampling: stride 2 halves the resolution.
  • Understanding this formula is a bread-and-butter interview requirement — several bug fixes in production code hinge on it.
Check yourself — multiple choice
  • Hout  =  HH_{\mathrm{out}}\; = \;H
  • HoutH_{\mathrm{out}} = ⌊(H + 2p − d(k−1) − 1)/s⌋ + 1
  • Hout  =  HH_{\mathrm{out}}\; = \;H·s + k
  • Hout  =  H/kH_{\mathrm{out}}\; = \;H / k

Standard conv output-size formula — includes padding and dilation.

#cnn#fundamentals

Practise Deep Learning

214 interview questions in this topic.

Related questions