Skip to content
AI360Xpert
Beta

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.

Each input value stamps a 3-weight kernel with stride 2, overlapping stamps sum, and a 14 by 14 map doubles to 28 by 28.
Each input value stamps a 3-weight kernel with stride 2, overlapping stamps sum, and a 14 by 14 map doubles to 28 by 28.

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 II, kernel KK, stride SS, padding PP, and output padding OPOP, the output size is O=(I−1)⋅S−2P+K+OPO = (I - 1) \cdot S - 2P + K + OP. Here II is the input side length, KK is the kernel side, SS is the step between stamps, PP trims the border, and OPOP adds the final row when doubling needs it. A 1414 by 1414 map through K=3K = 3, S=2S = 2, P=1P = 1 gives (14−1)⋅2−2+3=27(14 - 1) \cdot 2 - 2 + 3 = 27, plus OP=1OP = 1 to reach exactly 2828. 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 K=3K = 3 and S=2S = 2 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 x=[2,1]x = [2, 1], kernel w=[1,2,1]w = [1, 2, 1], stride S=2S = 2. The output length is (2−1)⋅2+3=5(2 - 1) \cdot 2 + 3 = 5 cells, all starting at zero. Input 22 stamps [2,4,2][2, 4, 2] onto cells 0,1,20, 1, 2. Input 11 steps two forward and stamps [1,2,1][1, 2, 1] onto cells 2,3,42, 3, 4. Summing gives y=[2,4,3,2,1]y = [2, 4, 3, 2, 1], and the middle cell y2=2+1=3y_2 = 2 + 1 = 3 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 33, 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 O=(I−1)⋅S−2P+K+OPO = (I - 1) \cdot S - 2P + K + OP, so 14 doubles to 28 with K3 S2 P1 OP1.
  • Inputs [2,1][2, 1] through kernel [1,2,1][1, 2, 1] at stride 2 give [2,4,3,2,1][2, 4, 3, 2, 1] with overlap cell 33.
  • 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.