Search

Search papers and lessons

Transposed Convolution

Level 3 · 13 min read

A transposed convolution spreads each input value out through a kernel, so it grows a small feature map into a larger one. Networks use it to upsample, but it is not an inverse of convolution.

On this page

  • Colour = topic mix
  • Calculus
  • Linear algebra
  • Architectures
  • Discrete math
  • Sign in to see your progress

TL;DR

A transposed convolution takes a small grid of numbers and produces a larger one. Each input value is multiplied by every weight in a small kernel, and those scaled copies are added together at the positions they land on. The operation has a learnable kernel, so the network decides how to fill in the bigger grid.

It is the usual tool for upsampling inside a network, such as turning a coarse feature map back into a full-resolution image. Despite the common name "deconvolution", it does not undo a convolution.

Where you'll see it: in the decoder half of image segmentation networks such as U-Net, in generators that turn a noise vector into an image, and in autoencoders that rebuild their input.

Intuition

A normal convolution looks at a window of inputs and produces one output. It gathers. A transposed convolution goes the other way. Each input value is a sender. It pushes a scaled copy of the kernel onto the output grid, starting at its own position. Where several senders reach the same output cell, their contributions add up.

Why would a network want this? Most of a convolutional network makes the picture smaller and more abstract. A classifier ends with a single label. A segmentation model, though, must label every pixel, and an image generator must produce a full picture. Something has to make the grid bigger again. Fixed rules such as nearest-neighbour or bilinear resizing do this with no learning. A transposed convolution does it with a kernel the network trains, so the enlarged picture can contain patterns the training data calls for, such as sharp edges or textures.

The name is worth a moment. Convolution is a matrix product with a banded matrix, and transposing that matrix gives the transposed convolution. The original maps a long signal to a short one, so the transpose maps a short one to a long one. It runs backwards in shape, not in meaning.

The plot below shows the simplest case: a stride-2 transposed convolution with a kernel of width 2 turns the input [1,10][1, 10] into four values. The two inputs are spaced two output cells apart, so the output doubles in length.

00.511.522.5305101520position in the output gridvalue
  • input [1, 10] (two values)
  • transposed output [1, 2, 10, 20] (four values)
Each input value is spread out by the kernel, and the output is twice as long as the input.

The flow below shows where the operation sits in a segmentation network. The encoder shrinks the image with ordinary convolutions and pooling. The decoder grows it again with transposed convolutions.

flowchart LR
  A[Input image 32x32] --> B[Convolutions and pooling]
  B --> C[Coarse features 8x8]
  C --> D[Transposed convolution x2]
  D --> E[Features 16x16]
  E --> F[Transposed convolution x2]
  F --> G[Full-resolution output 32x32]

The math

Convolution as a matrix

Take a one-dimensional input x\mathbf{x} of length nn and a kernel w=(w1,…,wk)\mathbf{w} = (w_1, \dots, w_k) of length kk. The valid convolution used in deep learning (strictly speaking a cross-correlation, since the kernel is not flipped) produces an output y\mathbf{y} of length m=n−k+1m = n - k + 1:

yi=∑j=1kwj xi+j−1,i=1,…,m.y_i = \sum_{j=1}^{k} w_j \, x_{i+j-1}, \qquad i = 1, \dots, m.

Each output is a dot product of the kernel with a window of the input. That means the whole operation is a matrix product y=Cx\mathbf{y} = C\mathbf{x}, where CC is an m×nm \times n matrix with entries

Ci, i+j−1=wj,all other entries 0.C_{i,\,i+j-1} = w_j, \qquad \text{all other entries } 0.

Each row of CC is the kernel, shifted one place to the right. A matrix like this, with constant diagonals, is called banded. See Matrix Multiplication for the matrix product itself.

The transposed convolution

The transposed convolution uses the transpose C⊤C^\top, which is an n×mn \times m matrix. Given a vector z\mathbf{z} of length mm, it returns a vector of length nn:

x′=C⊤z,xl′=∑i, j: i+j−1=lwj zi.\mathbf{x}' = C^\top \mathbf{z}, \qquad x'_l = \sum_{i,\,j:\ i+j-1 = l} w_j \, z_i.

The second form is the one to remember. Each ziz_i is a sender. It adds wjziw_j z_i to output position i+j−1i + j - 1 for every jj, which is the "spread out and add" picture from the intuition section. Position ll collects a contribution from every output ziz_i whose window covers it.

It is the transpose of a linear map, so it is linear in the input and in the kernel, and it trains with ordinary backpropagation.

Stride and output size

Let the stride be ss, meaning the senders are placed ss cells apart. For an input of length nn and a kernel of length kk, with no padding, the output length is

n′=(n−1) s+k.n' = (n - 1)\,s + k.

With stride 11 this is n+k−1n + k - 1, the full convolution. With stride 22 and k=2k = 2 it is 2n2n, so the length doubles. With padding pp removed from each end, the length becomes (n−1)s+k−2p(n-1)s + k - 2p.

Stride is what makes this an upsampler. The output grid is roughly ss times longer than the input grid.

Equivalent view: a convolution on a zero-filled input

The same operation can be written as an ordinary convolution. Insert s−1s - 1 zeros between neighbouring input values, add k−1k - 1 zeros at each end, and convolve with the kernel flipped left to right. This is the form most libraries use internally, and it is why the operation is sometimes called a fractionally strided convolution: the stride is effectively 1/s1/s.

Worked examples

Example
A tiny matrix, by hand

Take the input x=(1,2,3)\mathbf{x} = (1, 2, 3) and the kernel w=(1,2)\mathbf{w} = (1, 2). Here n=3n = 3, k=2k = 2, so m=2m = 2.

  1. Forward convolution: y1=1⋅1+2⋅2=5y_1 = 1 \cdot 1 + 2 \cdot 2 = 5 and y2=1⋅2+2⋅3=8y_2 = 1 \cdot 2 + 2 \cdot 3 = 8. So y=(5,8)\mathbf{y} = (5, 8).
  2. As a matrix, C=(120012)C = \begin{pmatrix} 1 & 2 & 0 \\ 0 & 1 & 2 \end{pmatrix}. Check: Cx=(1+4, 2+6)=(5,8)C\mathbf{x} = (1+4,\ 2+6) = (5, 8).
  3. Transposed convolution of z=(1,10)\mathbf{z} = (1, 10): C⊤z=(102102)(110)=(1, 12, 20)C^\top \mathbf{z} = \begin{pmatrix} 1 & 0 \\ 2 & 1 \\ 0 & 2 \end{pmatrix}\begin{pmatrix} 1 \\ 10 \end{pmatrix} = (1,\ 12,\ 20).
  4. In the scatter view: z1=1z_1 = 1 adds (1,2,0)(1, 2, 0), and z2=10z_2 = 10 adds (0,10,20)(0, 10, 20). The sum is (1,12,20)(1, 12, 20), the same result.
  5. Interpretation: the output has length 3 again, the original input length. The transposed convolution has restored the shape, not the values. Applying it to y\mathbf{y} gives C⊤y=(5, 18, 16)C^\top \mathbf{y} = (5,\ 18,\ 16), which is not x\mathbf{x}.
Example
Doubling a signal with stride 2

Take the input z=(1,10)\mathbf{z} = (1, 10), a kernel w=(1,2)\mathbf{w} = (1, 2), and stride s=2s = 2.

  1. Output length: (2−1)⋅2+2=4(2 - 1) \cdot 2 + 2 = 4.
  2. Place each sender at position 2i2i and spread the kernel from there. The first value, 11, adds (1,2)(1, 2) at positions 0 and 1. The second value, 1010, adds (10,20)(10, 20) at positions 2 and 3.
  3. Stack the results: (1,2,0,0)+(0,0,10,20)=(1,2,10,20)(1, 2, 0, 0) + (0, 0, 10, 20) = (1, 2, 10, 20).
  4. Check with the zero-filled view: insert one zero between the inputs to get (1,0,10)(1, 0, 10), pad one zero on each side to get (0,1,0,10,0)(0, 1, 0, 10, 0), and convolve with the flipped kernel (2,1)(2, 1). The outputs are 1,2,10,201, 2, 10, 20. Same answer.
  5. Interpretation: each input value now controls its own pair of output cells. The two pairs do not touch, so nothing is added twice.
Example
Overlap and the checkerboard

Keep the input z=(1,10)\mathbf{z} = (1, 10) but change the kernel to w=(1,1,1)\mathbf{w} = (1, 1, 1), width 3, with stride 2.

  1. Output length: (2−1)⋅2+3=5(2 - 1) \cdot 2 + 3 = 5.
  2. The first sender, 11, adds (1,1,1)(1, 1, 1) at positions 0, 1 and 2. The second, 1010, adds (10,10,10)(10, 10, 10) at positions 2, 3 and 4.
  3. Position 2 is covered by both senders, so it receives 1+10=111 + 10 = 11. Every other position receives a single contribution.
  4. Output: (1,1,11,10,10)(1, 1, 11, 10, 10).
  5. Interpretation: the middle value is larger than its neighbours for no reason in the input. When the kernel width is not a multiple of the stride, some cells are covered more often than others. Repeated over a 2D image, this becomes the grid pattern known as a checkerboard artifact.
Example
A realistic decoder step

A decoder receives a feature map of size 8×88 \times 8 with 64 channels and must produce 16×1616 \times 16 with 32 channels. A common setting is kernel 4×44 \times 4, stride 2, padding 1.

  1. Output side length: (8−1)⋅2+4−2⋅1=16(8 - 1) \cdot 2 + 4 - 2 \cdot 1 = 16. The spatial size doubles, as intended.
  2. Each pair of input and output channels needs its own 4×44 \times 4 kernel, which is 16 weights. That gives 64×32×16=32,76864 \times 32 \times 16 = 32{,}768 weights, plus 32 biases.
  3. The same layer with kernel 2×22 \times 2 and stride 2 gives (8−1)⋅2+2=16(8 - 1) \cdot 2 + 2 = 16 with no padding. It has 64×32×4=8,19264 \times 32 \times 4 = 8{,}192 weights, and every output cell is covered exactly once, so no checkerboard forms.
  4. Interpretation: kernel 4 with stride 2 is more flexible and still divisible by the stride, so its overlap is even. Kernel 2 is cheaper but has less room to learn smooth interpolation.

Tradeoffs and failure modes

Transposed convolution is a learned upsampler, which makes it powerful and easy to misuse. The table below lists the common situations.

SituationProblemBetter choice
Kernel width not divisible by stride (for example k=3k = 3, s=2s = 2)Uneven overlap gives a checkerboard pattern in the outputUse kk divisible by ss, such as k=2k = 2 or 44 with s=2s = 2
Need to recover the original signal exactlyTransposed convolution is not the inverse of convolution, so values are not restoredA trained autoencoder, or an invertible layer if exact reconstruction is the goal
Very large upsampling factorMany overlapping steps, slow, and prone to artifactsUpsample in several smaller steps
Upsampling should be smooth and predictableLearned kernels can produce blocky or noisy results with little dataResize (nearest or bilinear) followed by an ordinary convolution
Speed on tight hardware budgetsTransposed convolution is more expensive than a plain resizeResize plus a convolution, or sub-pixel convolution

Two practical warnings. "Deconvolution" suggests undoing a convolution, which this is not, so say "transposed convolution". And libraries differ in how they define padding and output padding here, so check the output shape on a small test input before building on it.

History

The operation appeared in several research threads before it had a standard name. In 2010, Zeiler, Krishnan, Taylor and Fergus used the transposed form in deconvolutional networks, which tried to reconstruct image layers from learned features. That work called it deconvolution, and the name stuck in the literature even though the operation is not an inverse.

Long, Shelhamer and Darrell's fully convolutional networks in 2015 made the idea central to dense prediction. They replaced the fully connected layers of a classifier with convolutions and used learned upsampling to produce a full-resolution segmentation map. Ronneberger, Fischer and Brox's U-Net, also in 2015, combined this decoder with skip connections from the encoder, and it became one of the most widely used segmentation architectures in medicine and beyond.

In 2016 Dumoulin and Visin wrote a systematic guide to convolution arithmetic. It set out the shape rules for strides, padding and transposed convolutions, and it pushed the term "transposed convolution" as the accurate name. The same year, Odena, Dumoulin and Olah published an analysis showing that uneven overlap causes checkerboard artifacts, which explained a visible problem many people had seen in generated images. The standard fixes are a kernel size divisible by the stride, or resizing before convolving.

Check yourself

QuestionA transposed convolution has input length nn, kernel length kk, stride 1 and no padding. What is its output length?Show answer

The formula is (n−1)⋅1+k=n+k−1(n - 1) \cdot 1 + k = n + k - 1. With stride 1, each input value adds a full copy of the kernel and the copies overlap, so the output is the full convolution length.

QuestionInput z=(2,3)\mathbf{z} = (2, 3), kernel w=(1,4)\mathbf{w} = (1, 4), stride 2. Compute the transposed convolution.Show answer

The output length is (2−1)⋅2+2=4(2 - 1) \cdot 2 + 2 = 4. The value 2 adds (2,8)(2, 8) at positions 0 and 1. The value 3 adds (3,12)(3, 12) at positions 2 and 3. The result is (2,8,3,12)(2, 8, 3, 12). Each input value is spread over its own pair of cells, and nothing overlaps.

QuestionIf you apply convolution to an image and then a transposed convolution with the same kernel, do you get the original image back? Why or why not?Show answer

No. Convolution with a kernel of width kk and stride 1 maps a length nn signal to length n−k+1n - k + 1, so information is lost at the edges and inside each window. The transposed convolution maps the shorter result back to length nn, but the matrix C⊤CC^\top C is not the identity. Its values are sums of kernel products, not the original pixels. Transposed convolution restores the shape, not the content.

QuestionA segmentation decoder upsamples a 16×1616 \times 16 feature map to 32×3232 \times 32 using a transposed convolution with kernel 3×33 \times 3 and stride 2 (with padding set to give the right size). A colleague sees a grid-like pattern in the predictions. What is the likely cause and how would you fix it?Show answer

The kernel width 3 is not divisible by the stride 2, so some output cells are covered by two senders and others by one. Those uneven sums produce the checkerboard. Fix it by changing the kernel to 2×22 \times 2 or 4×44 \times 4 so the overlap is even, or by replacing the layer with a nearest or bilinear resize followed by a 3×33 \times 3 convolution. Either approach removes the uneven coverage that causes the grid.

Sources