首页 > 解决方案 > 生成 300 * 300 * 3 图像的 GAN 的生成器和判别器模型的架构应该是什么?

问题描述

我经常看到人们生成 28 * 28 、 64 * 64 等的图像。为了创建这种大小的图像,他们通常从过滤器的数量开始 512、256、128 等等方式。通常它们在鉴别器和生成器中保持相同数量的层数。

我的第一个问题是创建 300 * 300 图像的鉴别器和生成器模型的架构应该是什么。

我的第二个问题是......在鉴别器和生成器中是否必须具有相同数量的层。如果我的鉴别器中的层数比生成器多怎么办?

我的第三个问题仅取决于第二个问题,我可以使用任何著名模型(如 resnet、vgg 等)的特征提取器部分来制作鉴别器吗?

PS 如果您正在编写架构代码,请在 pytorch 或 keras 中进行。

标签: kerasdeep-learningpytorchconv-neural-networkgenerative-adversarial-network

解决方案


  1. 生成器的架构完全取决于您想要的图像分辨率。如果需要输出更高分辨率的图像,则需要相应地修改图层的kernel_sizestride、 和。请参见以下示例:paddingConvTranspose2d
# 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。

  1. 在生成器和判别器中使用对称层的总体思路是,您希望两个网络都同样强大。他们与自己竞争并随着时间的推移学习。具有不对称层可能会导致训练时不平衡。

  2. 是的。您可以使用任何特征提取器来代替基本ConvConvTranspose图层。您可以将其ResidualBlock用作编码器ResidualBlockUp的一部分和解码器的一部分。


推荐阅读