Skip to content
SR-Forge

Adversarial

Adversarial losses for GAN training.

Provides vanilla and Relativistic average GAN (RaGAN) loss variants. Both use :class:~srforge.models.GANModel score fields from the Entry.

Vanilla GAN (recommended for UNet discriminators)::

d_criterion:
  _target: GANDiscriminatorLoss
  io: {inputs: {real_score: real_score_d, fake_score: fake_score_d}}
g_criterion:
  _target: GANGeneratorLoss
  io: {inputs: {fake_score: fake_score_g}}

Relativistic average GAN (RaGAN)::

d_criterion:
  _target: RaGANDiscriminatorLoss
  io: {inputs: {real_score: real_score_d, fake_score: fake_score_d}}
g_criterion:
  _target: RaGANGeneratorLoss
  io: {inputs: {real_score: real_score_g, fake_score: fake_score_g}}
References

Goodfellow et al., "Generative Adversarial Networks", NeurIPS 2014. Jolicoeur-Martineau, "The relativistic discriminator", ICLR 2019.

RaGANDiscriminatorLoss

Bases: Metric

Relativistic average discriminator loss.

Judges whether real images are more realistic than the average fake and vice-versa. Used during the discriminator update step.

calculate_score parameters (real_score, fake_score) must be bound to the D-step score fields via set_io.

RaGANGeneratorLoss

Bases: Metric

Relativistic average generator adversarial loss.

Pushes the generator to produce images that the discriminator considers more realistic than real images on average. Used during the generator update step (targets are flipped compared to :class:RaGANDiscriminatorLoss).

calculate_score parameters (real_score, fake_score) must be bound to the G-step score fields via set_io.

GANDiscriminatorLoss

Bases: Metric

Vanilla GAN discriminator loss.

Standard BCE: real should score 1, fake should score 0. Each image is scored independently — no relativistic coupling. Recommended for UNet spatial discriminators.

calculate_score parameters (real_score, fake_score) must be bound to the D-step score fields via set_io.

GANGeneratorLoss

Bases: Metric

Vanilla GAN generator loss — fool D into classifying fake as real.

Only needs the fake score (not real). The generator wants D to output 1 (real) for its generated images.

calculate_score parameter (fake_score) must be bound to the G-step fake score field via set_io.