Shaofanl / CycleGAN-keras

A Keras implementation of CycleGAN
24 stars 12 forks source link

identity loss is not correct #3

Open Trueyellow opened 6 years ago

Trueyellow commented 6 years ago

I found in cyclegan.py, you are using opt.idloss as the loss weight of identity loss

if opt.idloss > 0:
            G_trainner = Model([real_A, real_B], 
                     [dis_fake_B,   dis_fake_A,     rec_A,      rec_B,      fake_B,     fake_A])

            G_trainner.compile(Adam(lr=opt.lr, beta_1=opt.beta1,),
                loss=['MSE',        'MSE',          'MAE',      'MAE',      'MAE',      'MAE'],
                loss_weights=[1,    1,              opt.lmbd,   opt.lmbd,   opt.idloss  ,opt.idloss])

but, in the original pytorch version, they are using

if lambda_idt > 0:
            # G_A should be identity if real_B is fed.
            idt_A = self.netG_A(self.real_B)
            loss_idt_A = self.criterionIdt(idt_A, self.real_B) * lambda_B * lambda_idt  # loss part?

So I think the weight of identity loss should be opt.idloss*opt.lmbd?

Shaofanl commented 6 years ago

I implemented the code based on the paper. The only hyper-parameter in the Equ.3 is lambda. Feel free to change the code to include more tricks from the official repository.