GAN收敛失败,generator loss不断增加

问题描述

我正在尝试构建一个建议为 by this paper 的 SGAN。特别是,这个 SGAN 可以只将一张图像作为训练输入,并随机裁剪它以形成每个训练迭代的 minibatch。

这是我的训练样本:

enter image description here

我训练了我的模型 320 次迭代,并且每 10 次迭代保持生成器输出来自固定噪声,我得到的结果很糟糕:

enter image description here

最重要的是,我的发电机损失不断增加,突然下降:

enter image description here

有没有人知道如何解决这个问题?提前致谢。

P.S.,这是我的模型:

Discriminator(
  (main): Sequential(
    (0): Conv2d(1,64,kernel_size=(3,3),stride=(2,2),padding=(1,1)),640 params
    (1): BatchNorm2d(64,eps=1e-05,momentum=0.1,affine=True,track_running_stats=True),128 
params
    (2): LeakyReLU(negative_slope=0.2,inplace=True),0 params
    (3): Conv2d(64,128,73,856 params    
    (4): BatchNorm2d(128,256 params
    (5): LeakyReLU(negative_slope=0.2,0 params
    (6): Conv2d(128,256,295,168 params  
    (7): BatchNorm2d(256,512 params
    (8): LeakyReLU(negative_slope=0.2,0 params
    (9): Conv2d(256,1,2,305 params      
    (10): Sigmoid(),0 params
  ),372,865 params
),865 params

Generator(
  (main): Sequential(
    (0): ConvTranspose2d(20,kernel_size=(7,7),padding=(3,bias=False),250,880 params
    (1): BatchNorm2d(256,512 params
    (2): ReLU(inplace=True),0 params
    (3): ConvTranspose2d(256,605,632 params
    (4): BatchNorm2d(128,256 params
    (5): ReLU(inplace=True),0 params
    (6): ConvTranspose2d(128,401,408 params
    (7): BatchNorm2d(64,128 
params
    (8): ReLU(inplace=True),0 params
    (9): ConvTranspose2d(64,3,136 params
    (10): Tanh(),261,952 params
),952 params

还有我的训练代码:

for iteration in range(ITERATIONS):
############################
# (1) Update D network: maximize log(D(x)) + log(1 - D(G(z)))
###########################
miniBatch = getRandomMiniBatchFromSingleImage(trainSample,BATCH_SIZE)
miniBatch = miniBatch.to(DEVICE)
# train with real
netD.zero_grad()

output = netD(miniBatch)
errD_real = criterion(output,output.detach() * 0.0 + REAL_LABEL)
errD_real.backward()
D_x = output.mean().item()

# train with fake.
noise = torch.randn(BATCH_SIZE,Z_NO_OF_CHANNELS,Z_DIMENSION,device=DEVICE)
fake = netG(noise)
output = netD(fake.detach())
errD_fake = criterion(output,output.detach() * 0.0 + FAKE_LABEL)
errD_fake.backward()

D_G_z1 = output.mean().item()
errD = errD_real + errD_fake
optimizerD.step()

############################
# (2) Update G network: maximize log(D(G(z)))
###########################
netG.zero_grad()
output = netD(fake)
errG = criterion(output,output.detach() * 0.0 + REAL_LABEL)
errG.backward()
D_G_z2 = output.mean().item()
optimizerG.step()

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...