Concept

Preserving Dimensionality with Padding

In many convolutional neural network architectures, it is advantageous to keep the spatial height and width of the output identical to the input, making it easier to predict tensor shapes across deep networks. To preserve dimensionality when applying a kernel of size kextrmhimeskextrmwk_ extrm{h} imes k_ extrm{w}, we set the total number of padded rows to pextrmh=kextrmh1p_ extrm{h} = k_ extrm{h} - 1 and the total number of padded columns to pextrmw=kextrmw1p_ extrm{w} = k_ extrm{w} - 1. If the kernel dimension is odd, padding is distributed evenly (e.g., pextrmh/2p_ extrm{h}/2 rows on both sides). If the kernel dimension is even, padding is distributed asymmetrically, such as padding pextrmh/2ceil\lceil p_ extrm{h}/2 ceil rows on the top and pextrmh/2floor\lfloor p_ extrm{h}/2 floor rows on the bottom. Additionally, preserving dimensionality by using an odd-sized kernel and symmetric padding provides a useful clerical benefit: it guarantees that the output element Y[i,j]Y[i, j] is calculated with the convolution window centered exactly on the corresponding input element X[i,j]X[i, j].

0

1

Updated 2026-05-12

Contributors are:

Who are from:

Tags

D2L

Dive into Deep Learning @ D2L