gan
gan copied to clipboard
L1 loss problem with GAN if some data has ground-truth and some not
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!
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
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)