Compute the output shape of a 2D convolution with input (H, W), kernel k, stride s, padding p, dilation d.
mediumAnswer
- ((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
- = ⌊(H + 2p − d(k−1) − 1)/s⌋ + 1
- ·s + k
Standard conv output-size formula — includes padding and dilation.
#cnn#fundamentals
Practise Deep Learning
214 interview questions in this topic.
Related questions
- ReLU vs sigmoid vs GELU — when do you use each?
- What inductive biases do CNNs have?
- What is the receptive field in a CNN?
- In one sentence, what is backpropagation?
- State the universal approximation theorem in one sentence and its practical caveat.
- Why does stacking linear layers without nonlinearity collapse to a single linear layer?