eriklindernoren / PyTorch-GAN

PyTorch implementations of Generative Adversarial Networks.
MIT License
16.52k stars 4.09k forks source link

CycleGAN Error in Code (cyclegan.py) #118

Open jayroxis opened 4 years ago

jayroxis commented 4 years ago

In CycleGAN implementation, PyTorch-GAN/implementations/cyclegan/cyclegan.py line 180 and 181:

loss_id_A = criterion_identity(G_BA(real_A), real_A)
loss_id_B = criterion_identity(G_AB(real_B), real_B)

Obviously it is wrong, and I believe it's a typo. Should be correct to:

loss_id_A = criterion_identity(G_BA(real_B), real_A)
loss_id_B = criterion_identity(G_AB(real_A), real_B)
chenyang1999 commented 4 years ago

I do not think it's an error, criterion_identity is a mse loss in pixel-level, it is hard to minimize the loss(because of unpair images).

jayroxis commented 4 years ago

I do not think it's an error, criterion_identity is a mse loss in pixel-level, it is hard to minimize the loss(because of unpair images).

The G_BA maps domain B to domain A but in the above source code, it takes real_B as input which is unreasonable. The same for G_AB.

Example line 186~189 in cyclegan.py

fake_B = G_AB(real_A)
loss_GAN_AB = criterion_GAN(D_B(fake_B), valid)
fake_A = G_BA(real_B)
loss_GAN_BA = criterion_GAN(D_A(fake_A), valid)

It clearly shows that G_AB takes in domain A inputs while G_BA takes in domain B inputs.

Moreover, I checked other source of CycleGAN and I insists my point.

boyden commented 4 years ago

You are all not wrong. The original cycleGAN used the unpaired images as input, Without identity, the generator is free to change the style of the generated images. But we dont wanna much change about the color or contour except for style. Adding an identity loss will alleviate the problem, which is proved in the original unpaired cycleGAN paper. However, if we input paired images to cycleGAN, the identity loss should set as follows:

loss_id_A = criterion_identity(G_BA(real_B), real_A)
loss_id_B = criterion_identity(G_AB(real_A), real_B)