Effective convolution kernel size (source code)

= Effective convolution kernel size
{title2=$k_{\mathrm{eff}}=1+d(k-1)$}

The <effective convolution kernel size> is the bounding extent of a dilated <convolution kernel> along a spatial axis. For $k$ sampled coefficients with <convolution dilation> $d$, their offsets are $0,d,2d,\ldots,(k-1)d$. The first-to-last displacement is $d(k-1)$, so including the first position gives
$$
k_{\mathrm{eff}}=1+d(k-1).
$$
This extent determines the kernel footprint used in spatial shape calculations; it is not generally the number of coefficients.<Conv2d in the PyTorch documentation>[Dilation parameter; Shape, dilated spatial-extent terms]{ref}

For a two-dimensional example, choose a sampled kernel shape $(3,2)$ with dilation $(2,3)$. Its row offsets are $\{0,2,4\}$ and column offsets are $\{0,3\}$. The bounding shape is therefore
$$
(1+2(3-1),\,1+3(2-1))=(5,4).
$$
There are six sampled spatial positions inside a twenty-position <bounding box>. Fourteen intermediate positions are absent from the sampling pattern.

With three input <neural network channels> and four output channels, ordinary dense channel connectivity uses
$$
3\cdot2\cdot3\cdot4=72
$$
weights and optionally four biases, giving $76$ parameters. A general dense five-by-four kernel with the same channel counts would have $240$ weights. Representing the dilated operation that way would require $168$ of them to be fixed zeros, rather than independently learned parameters.<Conv2d in the PyTorch documentation>[Variables, weight dimensions versus dilation; groups=1]{ref}

For an unpadded $9$-by-$10$ input and <convolution stride> one, the output grid is
$$
(9-5+1)\times(10-4+1)=5\times7.
$$
More generally, for one axis with symmetric <zero padding> $p$ and stride $s$,
$$
L_{\mathrm{out}}=
\left\lfloor\frac{L+2p-k_{\mathrm{eff}}}{s}\right\rfloor+1
$$
when the padded input accommodates the footprint. The <floor function> counts admissible filter origins.<Conv2d in the PyTorch documentation>[Shape, per-axis output-size formulas]{ref}

The effective size is a geometric quantity for one layer. The complete <neural network receptive field> through several layers additionally depends on their kernels, strides and connections. Likewise, changing stride moves the spacing of origins; changing dilation changes the footprint at each origin. Keeping bounding extent, sampled-position count and learned-parameter count separate avoids confusing three different sizes.