Skip to content

Instantly share code, notes, and snippets.

@ethanyanjiali
Created June 6, 2019 05:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ethanyanjiali/512a1e4f0cb8a5ebb1ad3d9b008bbd02 to your computer and use it in GitHub Desktop.
Save ethanyanjiali/512a1e4f0cb8a5ebb1ad3d9b008bbd02 to your computer and use it in GitHub Desktop.
cyclegan_loss
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