class_docstr: The generator is a residual network.
class_docstr_tok: ["The","generator","is","a","residual","network","."]
code: def __init__(self, input_channels: int, n_residual_blocks: int):
      super().__init__()
      # This first block runs a $7\times7$ convolution and maps the image to
      # a feature map.
      # The output feature map has the same height and width because we have
      # a padding of $3$.
      # Reflection padding is used because it gives better image quality at edges.
      #
      # `inplace=True` in `ReLU` saves a little bit of memory.
      out_features = 64
      layers = [
          nn.Conv2d(
              input_channels,
              out_features,
              kernel_size=7,
              padding=3,
              padding_mode="reflect",
          ),
          nn.InstanceNorm2d(out_features),
          nn.ReLU(inplace=True),
      ]
      in_features = out_features
  
      # We down-sample with two $3 \times 3$ convolutions
      # with stride of 2
      for _ in range(2):
          out_features *= 2
          layers += [
              nn.Conv2d(
                  in_features,
                  out_features,
                  kernel_size=3,
                  stride=2,
                  padding=1,
              ),
              nn.InstanceNorm2d(out_features),
              nn.ReLU(inplace=True),
          ]
          in_features = out_features
  
      # We take this through `n_residual_blocks`.
      # This module is defined below.
      for _ in range(n_residual_blocks):
          layers += [ResidualBlock(out_features)]
  
      # Then the resulting feature map is up-sampled
      # to match the original image height and width.
      for _ in range(2):
          out_features //= 2
          layers += [
              nn.Upsample(scale_factor=2),
              nn.Conv2d(
                  in_features,
                  out_features,
                  kernel_size=3,
                  stride=1,
                  padding=1,
              ),
              nn.InstanceNorm2d(out_features),
              nn.ReLU(inplace=True),
          ]
          in_features = out_features
  
      # Finally we map the feature map to an RGB image
      layers += [
          nn.Conv2d(
              out_features,
              input_channels,
              7,
              padding=3,
              padding_mode="reflect",
          ),
          nn.Tanh(),
      ]
  
      # Create a sequential module with the layers
      self.layers = nn.Sequential(*layers)
  
      # Initialize weights to $\mathcal{N}(0, 0.2)$
      self.apply(weights_init_normal)
  
imports: import itertools
  import random
  import zipfile
  from typing import Tuple
  import torch
  import torch.nn
  import torchvision.transforms
  from PIL import Image
  from torch.utils.data import DataLoader, Dataset
  from torchvision.transforms import InterpolationMode
  from torchvision.utils import make_grid
  from labml import lab, tracker, experiment, monit
  from labml.configs import BaseConfigs
  from labml.utils.download import download_file
  from labml.utils.pytorch import get_modules
  from labml_helpers.device import DeviceConfigs
  from labml_helpers.module import Module
label_desc: Use image node_id 1 to create a new GeneratorResNet object from inherited base classes: Module with example: obj = GeneratorResNet(input_channels, n_residual_blocks)