pix2pix 学习笔记

利用condition-GAN,以一图输入作为condition,生成一图,以完成image-to-image translation这个任务,

而普通的GAN貌似只是噪声作为输入,

# D的loss定义
fake_B = netG(real_A)
fake_AB = torch.cat((real_A, fake_B))
predict_fake = netD(fake_AB)
loss_D_fake = loss(predict_fake, target=0)

real_AB = torch.cat((real_A, real_B))
predict_real = netD(real_AB)
loss_D_real = loss(predict_real, target=1)
loss_D = (loss_D_fake + loss_D_real) * 0.5


# G的loss定义
fake_B = netG(real_A)
fake_AB = torch.cat((real_A, fake_B))
predict_fake = netD(fake_AB)
loss_G_GAN = loss(predict_fake, target=1)
loss_G_L1 = L1_loss(fake_B, real_B) 
loss_G = loss_G_GAN + loss_G_L1

D的loss越小,意味着,real能区分 fake能区分,所以D的loss越大越好;
G的loss也是D给的,越小,意味着,fake接近real,所以G的loss越小越好。

你可能感兴趣的:(pix2pix 学习笔记)