Skip to content

CycleGAN

CycleGAN class

dlf.models.cycle_gan.CycleGAN(
    input_shape,
    generator="unet",
    generator_filters=32,
    discriminator_filters=64,
    use_perceptual_loss=True,
    cycle_weight=10.0,
    identity_weight=1.0,
    model_weights=None,
    summary=False,
    optimizer=None,
    resnet_blocks=9,
    **kwargs
)

A CycleGAN implementation

This class contains a CycleGAN implemenation with an U-Net architecture as generator. Next to the default implementation of a cycle adversarial loss, mentioned in CycleGAN paper, this implementations allows it to add an optional perceptual loss function.

Aliases

  • cycle_gan
  • CycleGAN

Args

  • input_shape: tuple(int, int , int). Input shape of this network
  • generator: str {'unet', 'resnet'}. Defines the generator type. Defaults to unet
  • generator_filters: int, optional. Number of CNN filters used for generator. Defaults to 32.
  • discriminator_filters: int, optional. Number of CNN filters used for discriminator. Defaults to 64.
  • use_perceptual_loss: bool, optional. If true, in addition to the CycleGAN implementated losses the perceptual loss is used. Defaults to True.
  • cycle_weight: float, optional. Weight for cycle consistency loss. Defaults to 10.0.
  • identity_weigh: float, optional. Weight for identity loss Defaults to 1.0.
  • model_weights: str, optional. Path to the pretrained model weights. Defaults to None.
  • summary: bool, optional. If true a summary of the model will be printed to stdout. Defaults to False.
  • optimizer: list of dict, optional. Name of optimizer used for training.
  • resnet_blocks: int. Only available if generator is resnet. Defaults to 9.

Raises

  • ValueError: If not exactly four optimizer are specified

YAML Configuration

model:
    cycle_gan:
        input_shape:
            - 512
            - 512
            - 3
        generator: unet
        generator_filters: 32
        discriminator_filters: 64
        use_perceptual_loss: False
        summary: True
        optimizer:
            - Adam:
                learning_rate: 0.0002
                beta_1: 0.5
            - Adam:
                learning_rate: 0.0002
                beta_1: 0.5
            - Adam:
                learning_rate: 0.0002
                beta_1: 0.5
            - Adam:
                learning_rate: 0.0002
                beta_1: 0.5

References

  • CycleGAN: https://arxiv.org/abs/1703.10593
  • U-Net: https://arxiv.org/abs/1505.04597
  • Perceptual Loss: https://cs.stanford.edu/people/jcjohns/papers/eccv16/JohnsonECCV16.pdf
  • https://www.tensorflow.org/tutorials/generative/cyclegan
  • https://github.com/eriklindernoren/Keras-GAN/blob/master/cyclegan/cyclegan.py