liveBook · Manning

Transposed convolution

As explained in Build a Text-to-Image Generator (from Scratch)

A transposed convolutional layer increases spatial resolution by applying a learned convolution-like operation that can expand spatial dimensions.

A transposed convolutional layer is a learned convolution-like operation that upsamples feature maps, fills gaps, and usually produces a larger spatial output than its input. Unlike ordinary convolution, it increases resolution rather than reducing it. section 6.2.3

Its role in a U-Net follows a practical sequence:

  • Start with compressed features produced by the contracting path and bottleneck. section 6.2.2
  • Apply a transposed convolution to increase spatial resolution; choose the stride to control the amount of upsampling. section 6.2.3
  • Combine the upsampled features with matching features from the contracting path through skip connections, preserving fine-grained spatial details. section 6.5
  • Process the result with additional convolutional or residual blocks to continue reconstructing the image. section 6.3.1

A 2 × 2 PyTorch operation

Create a one-channel ConvTranspose2d layer with a 2 × 2 kernel and stride 2. For input [[0, 1], [1, 2]] and weights [[1, 2], [2, 3]], the operation produces a 4 × 4 output: [[0, 0, 1, 2], [0, 0, 2, 3], [1, 2, 2, 4], [2, 3, 4, 6]]. section 6.2.3

class UnetUp(nn.Module):
    def __init__(self, in_channels, out_channels):
        super().__init__()
        layers = [nn.ConvTranspose2d(in_channels,
                                     out_channels, 2, 2),
            ResidualConvBlock(out_channels, out_channels),
            ResidualConvBlock(out_channels, 
            out_channels),]  #1
        self.model = nn.Sequential(*layers)
    def forward(self, x, skip):
        x = torch.cat((x, skip), 1)
        x = self.model(x)
        return x

The UnetUp implementation concatenates skip features, applies ConvTranspose2d with kernel size 2 and stride 2, then runs two residual convolutional blocks. section 6.3.1

How Build a Text-to-Image Generator (from Scratch) covers it

How deep it goes
Explains output growth, stride control, kernel application, and a worked 2D calculation, then implements the layer in PyTorch.
Examples
Uses a hand-weighted 2 × 2 image example and a PyTorch UnetUp implementation.
What it assumes
Assumes familiarity with feature maps and convolutional networks while explaining downsampling, bottlenecks, and upsampling in context.
What you can do after
Build it from scratch by configuring ConvTranspose2d and placing it inside a U-Net up block.
How it connects
Connects transposed convolution to U-Net, bottlenecks, skip connections, max pooling, feature maps, and residual convolutional blocks.

Also explained in

Compare how 5 books explain transposed convolution →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build a Text-to-Image Generator (from Scratch). The section links point to the parts of the book it draws on.