Formula

Formula for Convolution Output Size with Stride and Padding

When applying a convolution with kernel height khk_\textrm{h} and width kwk_\textrm{w}, total padding height php_\textrm{h} and width pwp_\textrm{w}, and strides shs_\textrm{h} and sws_\textrm{w}, the shape of the output generated from an input of height nhn_\textrm{h} and width nwn_\textrm{w} is:

(nhkh+ph+sh)/sh×(nwkw+pw+sw)/sw\lfloor(n_\textrm{h}-k_\textrm{h}+p_\textrm{h}+s_\textrm{h})/s_\textrm{h}\rfloor \times \lfloor(n_\textrm{w}-k_\textrm{w}+p_\textrm{w}+s_\textrm{w})/s_\textrm{w}\rfloor

This formula simplifies under certain conditions. If padding is set to ph=kh1p_\textrm{h}=k_\textrm{h}-1 and pw=kw1p_\textrm{w}=k_\textrm{w}-1, the output shape reduces to (nh+sh1)/sh×(nw+sw1)/sw\lfloor(n_\textrm{h}+s_\textrm{h}-1)/s_\textrm{h}\rfloor \times \lfloor(n_\textrm{w}+s_\textrm{w}-1)/s_\textrm{w}\rfloor. Furthermore, if the input dimensions are exactly divisible by the strides, the output shape simplifies to (nh/sh)×(nw/sw)(n_\textrm{h}/s_\textrm{h}) \times (n_\textrm{w}/s_\textrm{w}).

0

3

Updated 2026-05-12

Tags

Data Science

D2L

Dive into Deep Learning @ D2L