Definition
Transposed convolution (also fractionally-strided convolution, often mis-called deconvolution) is the linear map whose matrix is the transpose of a strided convolution's matrix. If a stride- convolution maps a large input to a small output , the transposed convolution with the same kernel maps a small input to a large output . Mechanically, every input value multiplies the whole kernel and is added into the output starting at position .
Encoder-decoder networks need a layer that goes the other way: from a coarse feature map back to a fine one. Fixed interpolation (nearest, bilinear) can do this but cannot learn. A transposed convolution is the learnable version, and it also appears automatically in every CNN, because it is exactly what backpropagation computes for the gradient of a strided convolution with respect to its input.
The name "deconvolution" comes from Zeiler, Krishnan, Taylor and Fergus's Deconvolutional Networks (2010) and from Zeiler and Fergus's 2014 "deconvnet" visualisations, and the term stuck. It is a misnomer: deconvolution in signal processing means inverting a convolution, while is only the adjoint and does not undo . Long, Shelhamer and Darrell's FCN (CVPR 2015) called it "backwards strided convolution" and used it, initialised to bilinear interpolation, to upsample segmentation scores; Dumoulin and Visin's A guide to convolution arithmetic for deep learning (2016) fixed the modern name and the shape rules. Radford, Metz and Chintala's DCGAN (ICLR 2016) built its generator entirely from them, and U-Net (Ronneberger, Fischer and Brox, 2015) uses "up-convolutions" in its decoder.
Formula and output size
- stride: how far apart consecutive input pixels stamp their kernel copies in the output (the upsampling factor)
- padding: here it crops pixels from each side of the full output (the opposite of padding in a convolution)
- kernel size; each input pixel touches outputs per axis
- extra rows/columns added on one side only, value , to choose among the input sizes that a stride- conv maps to the same
For 2-D the same holds per axis. Common configurations: gives exactly (; the DCGAN layer); also gives with no overlap (U-Net). The , stride-2, padding-1 convolution maps both and to , so its transpose is ambiguous: , and output_padding=1 selects .
Three equivalent views
The same operation, three ways
- 1Scatter. For each input pixel, add into the output at offset ; overlapping stamps are summed; then crop from each side.
- 2Insert zeros, then convolve. Put zeros between input pixels (length ), pad each side with zeros (plus
output_paddingon one side), and run an ordinary stride-1 convolution with the flipped kernel. The length works out to . This is why it is called fractionally strided: it behaves like a convolution with stride . - 3Matrix transpose. Write the stride- conv as a sparse matrix (one row per output, the kernel shifted by per row). The transposed conv multiplies by . For any and , .
The third view gives the gradients for free. If and , then : the backward pass of a transposed convolution is an ordinary strided convolution with the same kernel, and vice versa. The weight gradient is .
- the matrix of the stride- convolution with kernel , shape
- its transpose: the transposed convolution, shape
Worked example in 1-D
Let , , , . The output length is . Input 0 stamps at positions 0–2, input 1 stamps at 2–4, input 2 stamps at 4–6:
| output position | 0 | 1 | 2 | 3 | 4 | 5 | 6 |
|---|---|---|---|---|---|---|---|
| x[0]·w | 1 | 2 | 1 | ||||
| x[1]·w | 2 | 4 | 2 | ||||
| x[2]·w | 3 | 6 | 3 | ||||
| y (sum) | 1 | 2 | 3 | 4 | 5 | 6 | 3 |
| stamps overlapping | 1 | 1 | 2 | 1 | 2 | 1 | 1 |
Positions 2 and 4 receive two stamps, the others one: with and the overlap alternates . With the output is cropped to , and with , output_padding=1 it is . The zero-insertion view gives the same numbers: correlated with the (here symmetric) flipped kernel.
Adjoint check and gradients, upstream gradient g = (1, 0, 2, 1, 0, 1, 3)
- 1The stride-2 conv of with reads windows : .
- 2Adjoint identity: and .
- 3So for the input gradient is : a strided convolution.
- 4Weight gradient: gives .
Checkerboard artifacts
Feed an all-ones input through an all-ones kernel and every output pixel counts how many stamps land on it. Away from the border these counts take the values and per axis, so they are uniform only if divides . In 2-D the count map is the outer product of the 1-D counts: for the interior alternates , a checkerboard with a 4:1 ratio. Odena, Dumoulin and Olah ("Deconvolution and Checkerboard Artifacts", Distill 2016) showed that GAN and super-resolution outputs inherit exactly this pattern, and that stacking layers compounds it at several scales.
Choosing divisible by (; ) evens out the overlap, but the network can still learn uneven kernels that bring the artifacts back. Odena et al. recommend resize-convolution instead: upsample with nearest-neighbour or bilinear interpolation, then apply an ordinary stride-1 convolution. Every output then reads the same number of taps by construction. A third option is sub-pixel convolution (pixel shuffle, Shi et al. 2016): a stride-1 conv produces times the channels and nn.PixelShuffle rearranges them into an larger map; it is equivalent to a transposed convolution with a kernel of size , and benefits from an initialisation that makes the sub-kernels identical (ICNR, Aitken et al. 2017).
1import torch, torch.nn as nn, torch.nn.functional as F23# Note the weight layout: (in_channels, out_channels // groups, kH, kW), reversed vs Conv2d4up = nn.ConvTranspose2d(512, 256, kernel_size=4, stride=2, padding=1)5print(up.weight.shape) # torch.Size([512, 256, 4, 4])6print(up(torch.randn(1, 512, 8, 8)).shape) # torch.Size([1, 256, 16, 16])7print(sum(p.numel() for p in up.parameters())) # 209740889# output_padding picks between the sizes a stride-2 conv would collapse10t = nn.ConvTranspose2d(8, 8, 3, stride=2, padding=1)11print(t(torch.randn(1, 8, 7, 7)).shape) # 13 x 1312print(t(torch.randn(1, 8, 7, 7), output_size=(14, 14)).shape) # 14 x 14 (sets output_padding=1)1314# 1-D worked example15x = torch.tensor([[[1., 2, 3]]])16w = torch.tensor([[[1., 2, 1]]])17print(F.conv_transpose1d(x, w, stride=2).flatten().tolist()) # [1, 2, 3, 4, 5, 6, 3]1819# Adjoint: <conv(g), x> == <g, conv_transpose(x)>20g = torch.tensor([[[1., 0, 2, 1, 0, 1, 3]]])21print((F.conv1d(g, w, stride=2) * x).sum(), (g * F.conv_transpose1d(x, w, stride=2)).sum()) # 26, 262223# Checkerboard-free alternative (Odena et al., 2016): resize, then convolve24resize_conv = nn.Sequential(nn.Upsample(scale_factor=2, mode="nearest"),25 nn.Conv2d(512, 256, kernel_size=3, padding=1))26print(resize_conv(torch.randn(1, 512, 8, 8)).shape) # torch.Size([1, 256, 16, 16])2728# DCGAN-style generator (PyTorch-tutorial widths): 1x1 -> 4 -> 8 -> 16 -> 32 -> 6429G = nn.Sequential(30 nn.ConvTranspose2d(100, 512, 4, 1, 0), nn.BatchNorm2d(512), nn.ReLU(True),31 nn.ConvTranspose2d(512, 256, 4, 2, 1), nn.BatchNorm2d(256), nn.ReLU(True),32 nn.ConvTranspose2d(256, 128, 4, 2, 1), nn.BatchNorm2d(128), nn.ReLU(True),33 nn.ConvTranspose2d(128, 64, 4, 2, 1), nn.BatchNorm2d(64), nn.ReLU(True),34 nn.ConvTranspose2d(64, 3, 4, 2, 1), nn.Tanh())35print(G(torch.randn(2, 100, 1, 1)).shape) # torch.Size([2, 3, 64, 64])Where it's used
Segmentation decoders
FCN upsamples coarse class scores with transposed convolutions initialised to bilinear interpolation (for : , weights per axis). U-Net's decoder uses , stride-2 up-convolutions that halve the channels before concatenating the skip connection.
Generators
DCGAN's generator is a stack of , stride-2 transposed convolutions with Batch normalization and ReLU; many later GANs and VAE decoders kept the pattern or switched to resize-convolution to avoid checkerboards.
Backprop of every strided conv
Autograd computes the input gradient of a strided Conv2d with a transposed convolution, so checkerboard patterns also appear in gradient-based visualisations and adversarial perturbations of strided networks.
Use when
- +Learnable upsampling with the same parameter count as a conv
- +Exactly the adjoint of a strided conv: clean shape and gradient algebra
- +One fused op, fast on GPUs; k = 4, s = 2, p = 1 is a reliable exact ×2
Avoid when
- −Checkerboard artifacts when s does not divide k, and sometimes even when it does
- −Confusing size rules: padding crops, output_padding disambiguates
- −Not an inverse, despite the name 'deconvolution'
- −Resize-conv or pixel shuffle are often preferred in modern generators and super-resolution
Check yourself
A ConvTranspose2d has kernel 4, stride 2, padding 1. What output size does it produce from a 16 × 16 input?
Check yourself
Which kernel/stride pair gives non-uniform overlap (a checkerboard) for an all-ones input?
Remember
- ✓A transposed conv scatters into the output at stride : .
- ✓It is the matrix transpose of a strided conv; its backward pass is that strided conv. It is not an inverse.
- ✓Equivalent to inserting zeros between inputs, padding by , and convolving with the flipped kernel.
- ✓Overlap counts are uniform only when divides ; otherwise you get checkerboard artifacts (Odena et al., 2016).
- ✓Alternatives: resize-convolution (upsample, then conv) and pixel shuffle. PyTorch:
nn.ConvTranspose2d, weight shape .