- The architecture of the Generator is completely dependent on the resolution of the image that you desire. If you need to output a higher resolution image, you need to modify the
kernel_size, stride, and padding of the ConvTranspose2d layers accordingly. See the below example:
# 64 * 64 * 3
# Assuming a latent dimension of 128, you will perform the following sequence to generate a 64*64*3 image.
latent = torch.randn(1, 128, 1, 1)
out = nn.ConvTranspose2d(128, 512, 4, 1)(latent)
out = nn.ConvTranspose2d(512, 256, 4, 2, 1)(out)
out = nn.ConvTranspose2d(256, 128, 4, 2, 1)(out)
out = nn.ConvTranspose2d(128, 64, 4, 2, 1)(out)
out = nn.ConvTranspose2d(64, 3, 4, 2, 1)(out)
print(out.shape) # torch.Size([1, 3, 64, 64])
# Note the values of the kernel_size, stride, and padding.
# 284 * 284 * 3
# Assuming the same latent dimension of 128, you will perform the following sequence to generate a 284*284*3 image.
latent = torch.randn(1, 128, 1, 1)
out = nn.ConvTranspose2d(128, 512, 4, 1)(latent)
out = nn.ConvTranspose2d(512, 256, 4, 3, 1)(out)
out = nn.ConvTranspose2d(256, 128, 4, 3, 1)(out)
out = nn.ConvTranspose2d(128, 64, 4, 3, 1)(out)
out = nn.ConvTranspose2d(64, 3, 4, 3, 1)(out)
print(out.shape) # torch.Size([1, 3, 284, 284])
# I have only increased the stride from 2 to 3 and you could see the difference in the output size. You can play with the values to get 300*300*3.
If you would like to generate a higher sized output, take a look at progressive GANs.
The general idea behind using symmetric layers in both the Generator and the Discriminator is that you want both the networks to be equally powerful. They compete against themselves and learn over time. Having asymmetric layers could cause imbalance while training.
Yes. You can use any feature extractor instead of the basic Conv and ConvTranspose layers. You can use the ResidualBlock as part of the encoder and ResidualBlockUp as part of the decoder.