simplegan.losses

The losses sub-module provides users with useful loss functions which can be used to train their models.

VanillaAutoencoder losses

class simplegan.losses.mse_loss[source]
Parameters:
  • y_true (tensor) – A tensor representing the orginal values
  • y_pred (tensor) – A tensor representing the predicted values by the network
Returns:

A tensor representing the pixel wise loss between orginal and predicted values

GAN losses

class simplegan.losses.gan_discriminator_loss[source]
Parameters:
  • real_output (tensor) – A tensor representing the real logits of discriminator
  • fake_output (tensor) – A tensor representing the fake logits of discriminator
Returns:

a tensor representing the sum of real and fake loss

class simplegan.losses.gan_generator_loss[source]
Parameters:fake_output (tensor) – A tensor representing the fake logits of discriminator
Returns:a tensor representing the generator loss

InfoGAN losses

class simplegan.losses.auxillary_loss[source]
Parameters:
  • disc_target (tensor) – a tensor representing the discriminator target ouput
  • disc_preds (tensor) – a tensor representing the prediction of discriminator
  • cont_trg (tensor) – a tensor representing the content of the target
  • cont_pred (tensor) – a tensor representing the predicted content
Returns:

a tensor representing the auxillary loss

Pix2Pix losses

class simplegan.losses.pix2pix_discriminator_loss[source]
Parameters:
  • disc_real_output (tensor) – A tensor representing the real logits of the discriminator
  • disc_fake_output (tensor) – A tensor representing the fake logits of the discriminator
Returns:

total loss of discriminator

class simplegan.losses.pix2pix_generator_loss[source]
Parameters:
  • disc_fake_output (tensor) – A tensor representing the fake logits of discriminator
  • fake (tensor) – A tensor representing the values from the generator
  • real (tensor) – A tensor representing the real values
  • l (int) – An integer to scale the l1 loss
Returns:

total loss of generator, total loss of GAN and L1 loss

CycleGAN losses

class simplegan.losses.cycle_loss[source]
Parameters:
  • real_img (tensor) – A tensor representing the real image
  • cycle_img (tensor) – A tensor representing the generated image
  • LAMBDA (int) – An integer to scale the loss
Returns:

a tensor representing the loss

class simplegan.losses.identity_loss[source]
Parameters:
  • real_img (tensor) – A tensor representing the real image
  • cycle_img (tensor) – A tensor representing the generated image
  • LAMBDA (int) – An integer to scale the loss
Returns:

a tensor representing the loss

Wasserstein losses

class simplegan.losses.wgan_discriminator_loss[source]
Parameters:
  • real_output (tensor) – a tensor representing the real logits of the discriminator
  • fake_output (tensor) – a tensor representing the fake logits of the discriminator
Returns:

total discriminator loss

class simplegan.losses.wgan_generator_loss[source]
Parameters:fake_output (tensor) – a tensor representing the fake logits of the discriminator
Returns:generator loss

Hinge losses

class simplegan.losses.hinge_loss_generator[source]
Parameters:generated_output (tensor) – A tensor of the generated image.
Returns:a tensor representing hinge loss.
class simplegan.losses.hinge_loss_discriminator[source]
Parameters:
  • real_output (tensor) – A tensor of real output.
  • generated_output (tensor) – A tensor of predictions made by discriminator.
Returns:

a tensor representing hinge loss.