- 生成器的架构完全取决于您想要的图像分辨率。如果需要输出更高分辨率的图像,则需要对
ConvTranspose2d层的kernel_size、stride和padding进行相应的修改。请参阅以下示例:
# 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.
如果您想生成更大尺寸的输出,请查看渐进式 GAN。
-
在生成器和判别器中使用对称层的总体思路是,您希望两个网络都同样强大。他们与自己竞争并随着时间的推移学习。具有不对称层可能会导致训练时不平衡。
-
是的。您可以使用任何特征提取器来代替基本的Conv 和ConvTranspose 层。您可以将ResidualBlock 用作编码器的一部分,将ResidualBlockUp 用作解码器的一部分。