code: def __init__(self):
      super(Generator, self).__init__()
  
      def convlayer(n_input, n_output, k_size=4, stride=2, padding=0):
          block = [
              nn.ConvTranspose2d(
                  n_input,
                  n_output,
                  kernel_size=k_size,
                  stride=stride,
                  padding=padding,
                  bias=False,
              ),
              nn.ReLU(inplace=True),
              nn.BatchNorm2d(n_output),
          ]
          return block
  
      self.project = nn.Sequential(
          nn.Linear(opt.latent_dim, 256 * 4 * 4),
          nn.BatchNorm1d(256 * 4 * 4),
          nn.ReLU(inplace=True),
      )
  
      # pytorch doesn't have padding='same' as keras does.
      # hence we have to pad manually to get the desired behavior.
      # from the manual:
      # o = (i−1)∗s−2p+k, i/o = in/out-put, k = kernel size, p = padding, s = stride.
  
      self.model = nn.Sequential(
          *convlayer(
              opt.latent_dim, 256, 4, 1, 0
          ),  # Fully connected layer via convolution.
          *convlayer(
              256, 128, 4, 2, 1
          ),  # 4->8, (4-1)*2-2p+4 = 8, p = 1
          *convlayer(128, 64, 4, 2, 1),  # 8->16, p = 1
          nn.ConvTranspose2d(64, opt.channels, 4, 2, 1),
          nn.Tanh(),
      )
  
file_path: gans-with-pytorch/dcgan/dcgan.py
imports: import argparse
  import os
  import torch
  from torch import nn, optim
  from torch.autograd.variable import Variable
  from torchvision import transforms, datasets
  from torch.utils.data import DataLoader
  from torchvision.utils import save_image
label_desc: Use image node_id 1 to create a new Generator object from inherited base classes: nn with example: obj = Generator()