gan icon indicating copy to clipboard operation
gan copied to clipboard

L1 loss problem with GAN if some data has ground-truth and some not

Open HymEric opened this issue 4 years ago • 2 comments

It's a great work.

If I want to use L1 loss between the generated image by generator and the ground-truth image, but some images have ground-truth and some others don't. That is to say, in a batch, some have ground-truth and some not. I only will use l1 loss with the images which have ground-truth.

In this problem, is there a way to address it?
Thank you!

HymEric avatar Dec 08 '20 12:12 HymEric

Hi @HymEric Maybe you could try using an external function such that g(ground-truth) --> generated, before using L1 loss, as mentioned in https://github.com/junyanz/pytorch-CycleGAN-and-pix2pix/issues/293#issuecomment-397740979

surya1701 avatar Feb 19 '21 05:02 surya1701

Generally the way you would do something like this in Tensorflow is to have some dummy value for the ground truth when it's not available (like an all 0's tensor, for example) and keep a binary mask of shape [batch_size] that has value 1 if there is ground truth and 0 otherwise. You can then use this as a weight applied to the per-sample loss. Your final loss would be something like: loss = tf.reduce_mean(weight_mask * tf.losses.mean_absolute_error(ground_truth, generated)

aaronsarna avatar Feb 19 '21 15:02 aaronsarna