TF 2.0 is out! Get hands-on practice at TF World, Oct 28-31. Use code TF20 for 20% off select passes. Register now


View source on GitHub

Defines the cycle consistency loss.


The cyclegan model has two partial models where model_x2y generator F maps data set X to Y, model_y2x generator G maps data set Y to X. For a data_x in data set X, we could reconstruct it by * reconstructed_data_x = G(F(data_x)) Similarly * reconstructed_data_y = F(G(data_y))

The cycle consistency loss is about the difference between data and reconstructed data, namely * loss_x2x = |data_x - G(F(data_x))| (L1-norm) * loss_y2y = |data_y - F(G(data_y))| (L1-norm) * loss = (loss_x2x + loss_y2y) / 2 where loss is the final result.

For the L1-norm, we follow the original implementation: we use L1-norm of pixel-wise error normalized by data size such that cycle_loss_weight can be specified independent of image size.

See for more details.


  • data_x: A Tensor of data X.
  • reconstructed_data_x: A Tensor of reconstructed data X.
  • data_y: A Tensor of data Y.
  • reconstructed_data_y: A Tensor of reconstructed data Y.
  • scope: The scope for the operations performed in computing the loss. Defaults to None.
  • add_summaries: Whether or not to add detailed summaries for the loss. Defaults to False.


A scalar Tensor of cycle consistency loss.