qq_40006118 2022-12-23 14:36 采纳率: 77.3%
浏览 33
已结题

GAN训练生成的图像不清晰且无法辨认

训练的CGAN,采用cifar10数据集,经过20次训练后已经能出现图像,但是图像不清晰,而且图像看不出是什么东西。

img

如图所示,请问是训练次数不够还是说训练方法有错?
这是生成器和判别器的代码

class DCDiscriminator(nn.Module)
   https://img-mid.csdnimg.cn/release/static/image/mid/ask/855452777176119.png "#left")
 def __init__(self)
        super(DCDiscriminator, self).__init__()
        self.dis=nn.Sequential(
            nn.Conv2d(3+10,64,4,2,1,bias=False),
            nn.LeakyReLU(0.2,inplace=True),

            nn.Conv2d(64,64*2,4,2,1,bias=False),
            nn.BatchNorm2d(64 * 2),
            nn.LeakyReLU(0.2, inplace=True),

            nn.Conv2d(64 * 2, 64 * 4, 4, 2, 1, bias=False),
            nn.BatchNorm2d(64 * 4),
            nn.LeakyReLU(0.2, inplace=True),

            nn.Conv2d(64 * 4, 64 * 8, 4, 2, 1, bias=False),
            nn.BatchNorm2d(64 * 8),
            nn.LeakyReLU(0.2, inplace=True),

            nn.Conv2d(64 * 8, 1, 4, 1, 0, bias=False),
            nn.Sigmoid()
        )
    def forward(self, x)
        return self.dis(x).view(-1, 1).squeeze(1)

class DCGenerator(nn.Module)
    def __init__(self)
        super(DCGenerator, self).__init__()
        self.gen=nn.Sequential(
            nn.ConvTranspose2d(100+10, 64 * 8, 4, 1, 0, bias=False),
            nn.BatchNorm2d(64 * 8),
            nn.ReLU(True),
            # state size. (ngf*8) x 4 x 4
            nn.ConvTranspose2d(64 * 8, 64 * 4, 4, 2, 1, bias=False),
            nn.BatchNorm2d(64 * 4),
            nn.ReLU(True),

            nn.ConvTranspose2d(64 * 4, 64 * 2, 4, 2, 1, bias=False),
            nn.BatchNorm2d(64 * 2),
            nn.ReLU(True),

            nn.ConvTranspose2d(64 * 2, 64, 4, 2, 1, bias=False),
            nn.BatchNorm2d(64),
            nn.ReLU(True),

            nn.ConvTranspose2d(64, 3, 4, 2, 1, bias=False),
            nn.Tanh()
        )

    def forward(self,x)
        return self.gen(x)


batch_size=128,learning_rate=0.0002

  • 写回答

1条回答 默认 最新

  • 沐凡星 2022-12-29 18:43
    关注

    loss函数弄错了吧

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 3月16日
  • 已采纳回答 3月8日
  • 创建了问题 12月23日

悬赏问题

  • ¥170 如图所示配置eNSP
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥15 键盘指令混乱情况下的启动盘系统重装