Abstract
We introduce a guide to help deep learning practitioners understand and manipulate convolutional neural network architectures. The guide clarifies the relationship between various properties (input shape, kernel shape, zero padding, strides and output shape) of convolutional, pooling and transposed convolutional layers, as well as the relationship between convolutional and transposed convolutional layers. Relationships are derived for various cases, and are illustrated in order to make them intuitive.
Introduction
In the development of deep learning architectures, practitioners often face challenges in managing the "geometry" of convolutional neural networks (CNNs). Unlike fully connected layers, where output dimensions are straightforward, a convolutional layer's output size is determined by a complex interplay between input dimensions, kernel size, padding, and stride. This technical guide, authored by Vincent Dumoulin and Francesco Visin, serves as a definitive reference for these geometric mechanics, providing a unified mathematical framework to replace architectural guesswork with rigorous arithmetic.
Methodology: Two Perspectives on Convolution
The authors analyze convolutions through two complementary lenses to derive their shape-mapping formulas.
The Sliding Window View
The most intuitive approach is the sliding window view, where a kernel of a specific size moves across an input grid. This perspective is essential for visualizing how local features are extracted and how the spatial dimensions are reduced or preserved.
The Matrix View
For a more formal mathematical treatment, the authors frame convolution as a sparse matrix transformation. In this view, a convolution is represented by a matrix $\mathbf{C}$ where weights are rearranged to reflect the sliding window operation. A forward pass is computed as $\mathbf{C}\mathbf{x}$, while the backward pass—and by extension, the transposed convolution—is computed as $\mathbf{C}^T\mathbf{y}$. This bridge allows transposed convolutions to be understood as "direct" convolutions performed on modified (e.g., padded or stretched) inputs.
Key Insights and Arithmetic
The guide provides precise formulas for various convolution types. A central theme is the use of zero padding to control the spatial extent of the output, allowing for "same" convolutions where input and output dimensions match.
Essential Formulas
The "cheat sheet" provided by the authors includes several critical mappings:
- Standard Convolution Output ($o$): $o = \left\lfloor \frac{i + 2p - k}{s} \right\rfloor + 1$, where $i$ is input size, $p$ is padding, $k$ is kernel size, and $s$ is stride.
- Transposed Convolution Output ($o'$): $o' = s(i' - 1) + a + k - 2p$, where $i'$ is the input to the transposed layer and $a$ is a parameter used to resolve shape ambiguity caused by the floor function in the direct convolution.
- Dilated Convolutions: These are treated as having an effective kernel size $\hat{k} = k + (k - 1)(d - 1)$, where $d$ is the dilation rate.
Transposed and Dilated Convolutions
The paper clarifies that transposed convolutions (often mislabeled as "deconvolutions") are not the mathematical inverse of convolutions but rather their transpose in terms of connectivity. Similarly, dilated convolutions are explained as "inflated" kernels that increase the receptive field without adding parameters, by inserting spaces between weights.
Limitations
While this guide is exhaustive regarding shape arithmetic and connectivity, it does not address computational efficiency on specific hardware (like GPUs). Furthermore, it focuses on the structural properties of layers rather than the qualitative effects of these operations, such as the "checkerboard artifacts" often associated with transposed convolutions in generative models. Newer variants like deformable or depthwise convolutions are also outside the scope of this fundamental arithmetic guide.
Summary updated