keras - 生成 300 * 300 * 3 图像的 GAN 的生成器和判别器模型的架构应该是什么?
问题描述
我经常看到人们生成 28 * 28 、 64 * 64 等的图像。为了创建这种大小的图像,他们通常从过滤器的数量开始 512、256、128 等等方式。通常它们在鉴别器和生成器中保持相同数量的层数。
我的第一个问题是创建 300 * 300 图像的鉴别器和生成器模型的架构应该是什么。
我的第二个问题是......在鉴别器和生成器中是否必须具有相同数量的层。如果我的鉴别器中的层数比生成器多怎么办?
我的第三个问题仅取决于第二个问题,我可以使用任何著名模型(如 resnet、vgg 等)的特征提取器部分来制作鉴别器吗?
PS 如果您正在编写架构代码,请在 pytorch 或 keras 中进行。
解决方案
- 生成器的架构完全取决于您想要的图像分辨率。如果需要输出更高分辨率的图像,则需要相应地修改图层的
kernel_size
、stride
、 和。请参见以下示例:padding
ConvTranspose2d
# 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
的一部分和解码器的一部分。
推荐阅读
- windows - 如何使用 PowerShell 以编程方式弹出锁定的 HDD eSATA 驱动器?
- php - 在 index.php 中加载所有页面时如何防止使用 php 进行会话劫持
- javascript - 我正在处理在 javascript 中附加行,但我实际上不知道如何在行单元格中附加图像
- reactjs - 解构获取的数据反应
- android - Android 应用程序 - 对齐 EditTexts 不起作用
- python - 循环函数时是否有更快的方法来返回多个值?
- android - 您正在使用的 compose 编译器插件(版本 1.0.0-alpha13)需要 1.0.0-alpha13 的最低运行时版本
- javascript - 如果用户输入错误的密码,如何停止导航?
- javascript - 我无法理解传递给 TypeORM 关系装饰器的回调语法
- php - PHP 如何使用 id 未给定参数验证 URL?