【问题标题】:What should be the architecture of the generator and discriminator model of the GAN for generating 300 * 300 * 3 images?生成 300 * 300 * 3 图像的 GAN 的生成器和判别器模型的架构应该是什么?
【发布时间】:2021-03-09 08:44:44
【问题描述】:

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

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

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

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

附:如果您正在编写架构代码,请在 pytorch 或 keras 中编写。

【问题讨论】:

    标签: keras deep-learning pytorch conv-neural-network generative-adversarial-network


    【解决方案1】:
    1. 生成器的架构完全取决于您想要的图像分辨率。如果需要输出更高分辨率的图像,则需要对ConvTranspose2d层的kernel_sizestridepadding进行相应的修改。请参阅以下示例:
    # 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 用作解码器的一部分。

    【讨论】:

    • 再次感谢您回复我的问题.....我猜您在 GAN 上工作得非常好。关于 GAN 的任何进一步建议。我真的很想听从你的建议。
    • 不客气!如果您希望模型生成高质量的输出,超参数调整非常重要。你会在这个过程中花费更多的时间。一些建议是处理输入归一化和相应的损失函数,使用跨步卷积而不是池化。对除鉴别器的输入和生成器的输出之外的所有层使用 BatchNorm。尽管 Adam 通常用作优化器,但我认为 SGD 也不会出错。您还需要在训练期间观察损失,因为这可以提供特定信息。
    猜你喜欢
    • 2020-09-22
    • 2018-06-06
    • 1970-01-01
    • 2018-07-23
    • 1970-01-01
    • 2021-06-24
    • 1970-01-01
    • 2017-10-11
    • 1970-01-01
    相关资源
    最近更新 更多