Created
June 6, 2019 05:59
-
-
Save ethanyanjiali/512a1e4f0cb8a5ebb1ad3d9b008bbd02 to your computer and use it in GitHub Desktop.
cyclegan_loss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def calc_gan_loss(prediction, is_real): | |
# Typical GAN loss to set objectives for generator and discriminator | |
if is_real: | |
return mse_loss(prediction, tf.ones_like(prediction)) | |
else: | |
return mse_loss(prediction, tf.zeros_like(prediction)) | |
def calc_cycle_loss(reconstructed_images, real_images): | |
# Cycle loss to make sure reconstructed image looks real | |
return mae_loss(reconstructed_images, real_images) | |
def calc_identity_loss(identity_images, real_images): | |
# Identity loss to make sure generator won't do unnecessary change | |
# Ideally, feeding a real image to generator should generate itself | |
return mae_loss(identity_images, real_images) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment