liveBook · Manning

Up block

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

An up block is a U-Net component that increases spatial resolution through operations such as transposed convolution.

An up block is the expansive-path component of a U-Net that increases feature-map resolution. It uses a 2D transposed convolution to upsample features, fill spatial gaps, and produce larger outputs than its input. section 6.2.3 section 6.3.1

Trace an up block through its main operations:

  • Receive the current feature representation and a skip-connection feature from the contracting path. section 6.3.1
  • Concatenate the current representation with the skip feature along the channel dimension. section 6.3.1
  • Apply ConvTranspose2d; its kernel and stride control how much spatial resolution increases. section 6.2.3 section 6.3.1
  • Refine the enlarged features with two residual convolutional blocks. section 6.3.1

A hand-worked transposed convolution

A 2 × 2 input with values [[0, 1], [1, 2]] passes through a one-channel ConvTranspose2d layer with a 2 × 2 kernel and stride 2. With weights [[1, 2], [2, 3]] and zero bias, the output becomes a 4 × 4 feature map, demonstrating how learned kernels expand resolution and fill gaps. 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

Inspect the compact PyTorch UnetUp implementation, including skip-feature concatenation, ConvTranspose2d, and residual convolutional refinement. section 6.3.1

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

How deep it goes
Explains resolution growth, stride effects, skip concatenation, and residual refinement, with a numerical operation and PyTorch implementation.
Examples
Uses a 2 × 2 tensor, hand-set kernel weights, stride 2, and a printed 4 × 4 transposed-convolution output.
What it assumes
Assumes basic convolutional-network and tensor knowledge while introducing transposed-convolution upsampling through small numerical examples.
What you can do after
Build it from scratch with PyTorch using ConvTranspose2d, tensor concatenation, and residual convolutional blocks.
How it connects
Connects U-Net, transposed convolution, skip connections, residual convolutional blocks, denoising diffusion models, and down blocks.

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.