eriklindernoren / PyTorch-GAN

PyTorch implementations of Generative Adversarial Networks.
MIT License
16.23k stars 4.05k forks source link

About the Identity loss in cyclegan.py #59

Closed LittleQuteSweetie closed 4 years ago

LittleQuteSweetie commented 5 years ago

The source code of Identity loss is shown below: loss_id_A = criterion_identity(G_BA(real_A), real_A) loss_id_B = criterion_identity(G_AB(real_B), real_B)

This seems a little bit weird to me, maybe it should be: loss_id_A = criterion_identity(G_AB(real_A), real_A) loss_id_B = criterion_identity(G_BA(real_B), real_B)

binli123 commented 5 years ago

I have the same concern.

busekuz commented 5 years ago

I think these issues from the original repo, especially the first one, might give you a better idea on what identity loss is. 1, 2

IvanFei commented 4 years ago

G_BA: domain B -> domain A, It wants to realize identity map, f(x) = x. In this case, If the input of G_BA is image in domain A (not in domain B), the output of G_BA should be the same as image in domain A.

As is shown in the picture (below) -> L_TID image

refer to Unsupervised Cross-Domain Image Generation and Unpaired Image-to-Image Translation using Cycle-Consistent Adversarial Networks

detailed explanation: https://github.com/junyanz/pytorch-CycleGAN-and-pix2pix/issues/322

LittleQuteSweetie commented 4 years ago

@IvanFei @busekuz Thanks for your answers! They are very helpful, especially the picture; I think now I do understand the identity loss.

Best Regards, LQS