Transposed Convolution
Transposed convolution learns how to upsample. Each input pixel stamps a small kernel onto a larger canvas, so decoders rebuild resolution step by step.
Why Does This Exist?
Encoders shrink images: 224 becomes 112, then 56, 28, 14. Segmentation and generation must climb back up to full resolution with one label per input pixel. Nearest-neighbour upsampling climbs back but learns nothing: every 2 by 2 block copies one value and boundaries stay blocky, so small objects keep stair-step edges no learned layer can later fix.
Transposed convolution makes the climb learnable. Each input value is multiplied by a small kernel and stamped onto the output canvas, with overlapping stamps summing where they land. With stride 2 and a 3 by 3 kernel each side doubles while the weights learn edge-aware interpolation instead of copying. This page covers that upsampling pass with its size arithmetic and overlap behavior. Downsampling lives in pooling and downsampling, basic layer shapes live in convolutional layers, and size arithmetic for the forward pass lives in basic CNN operations.
Think of It Like This
Stamping tiles that overlap at the edges
Press an inked 3 by 3 sponge once per grid cell on a larger sheet, stepping two cells each time so stamps overlap by one row. Where two stamps overlap the ink adds up, and the learned sponge pattern decides whether edges come out sharp or soft. Each input pixel is one press, the stride sets the step, and the overlap is where learning happens and where artifacts start.
The analogy stops at ink: sponge ink only adds, while real kernels hold negative weights that can subtract, and the pattern is learned by gradient descent rather than carved once.
How It Actually Works
The size rule
For input size , kernel , stride , padding , and output padding , the output size is . Here is the input side length, is the kernel side, is the step between stamps, trims the border, and adds the final row when doubling needs it. A by map through , , gives , plus to reach exactly . That is the doubling path decoders repeat stage after stage.
Stamps that overlap
Despite the old name, this layer is not a deconvolution and inverts nothing. It is the gradient-shaped twin of a convolution: the forward pass broadcasts each input across several outputs instead of gathering many inputs into one. Uneven overlap is the known trap. With and some output cells receive two stamps while neighbours receive one, so a random kernel prints a checkerboard. The fixes are a kernel size divisible by the stride (4 by 4 at stride 2 overlaps evenly), initialization to bilinear weights, or resize plus a regular convolution.
Worked 1D stamping
Take input , kernel , stride . The output length is cells, all starting at zero. Input stamps onto cells . Input steps two forward and stamps onto cells . Summing gives , and the middle cell is the overlap where two stamps land. Scale this picture to two dimensions and it is exactly what the diagram shows: every output is a sum of one or two stamped contributions.
Code
The point of this snippet is shape plus overlap: the size function confirms the 14 to 28 doubling, and the loop replays the worked stamping so the overlap sum can be checked.
def transposed_size(i, k=3, s=2, p=1, op=1): return (i - 1) * s - 2 * p + k + op
print(transposed_size(14))# -> 28print(transposed_size(7))# -> 14
x = [2, 1]w = [1, 2, 1]s = 2y = [0] * ((len(x) - 1) * s + len(w))for i, v in enumerate(x): for j, k in enumerate(w): y[i * s + j] += v * kprint(y)# -> [2, 4, 3, 2, 1]The 7 to 14 line is the same doubling one stage earlier in a decoder. The overlap cell holds , the sum of two stamps, which is why random kernels print grids and bilinear initialization calms them.
Watch Out For
Checkerboard artifacts on smooth outputs
A 3 by 3 stride-2 layer with random weights prints alternating bright and dark cells on skies and walls. The symptom is a visible grid in generated images that survives training. Use a 4 by 4 kernel at stride 2, initialize from bilinear weights, or switch to nearest resize followed by a 3 by 3 convolution.
Off-by-one shapes that break skip connections
A transposed layer returns 27 instead of 28 when output padding is forgotten, and concatenation with the encoder skip then crashes. The symptom is a channel-concat error naming mismatched heights at one decoder stage. Compute the size formula before training and assert the decoder map matches the skip map at every stage.
The Quick Version
- Transposed convolution upsamples by stamping a learned kernel per input pixel with overlapping sums.
- Size follows , so 14 doubles to 28 with K3 S2 P1 OP1.
- Inputs through kernel at stride 2 give with overlap cell .
- Kernel 3 at stride 2 overlaps unevenly and prints checkerboards on smooth regions.
- The layer learns interpolation instead of copying, and it inverts no convolution.