Stabilizing GAN training often involves modifying the loss function's underlying distance metric (like in WGANs) or applying regularization techniques (like Spectral Normalization). Relativistic GANs offer a different perspective on improving stability by fundamentally changing what the discriminator is asked to predict.
In a standard GAN formulation, the discriminator D tries to estimate the absolute probability that a given input x is real. Its output D(x) is often interpreted as P(xΒ isΒ real). The generator G is then trained to produce samples G(z) that maximize this probability D(G(z)).
Relativistic GANs propose that it might be more effective and stable for the discriminator to predict the relative probability that given real data is more realistic than fake data, sampled randomly. Instead of outputting an absolute score, the discriminator's task becomes comparative.
Let C(x) represent the output of the discriminator before the final activation function (e.g., sigmoid). In a standard GAN (SGAN), the discriminator loss involves terms like log(Ο(C(xrealβ))) and log(1βΟ(C(xfakeβ))), where Ο is the sigmoid function.
The Relativistic Average GAN (RaGAN)
A particularly effective variant is the Relativistic average GAN (RaGAN). Instead of comparing a single real sample to a single fake sample, RaGAN compares a sample (real or fake) against the average assessment of samples from the opposing distribution.
The core idea is formalized in the RaSGAN (Relativistic average Standard GAN) loss functions. The discriminator D is trained to maximize:
LDRaSGANβ=βExrealββΌPrealββ[log(Οrealβ)]βExfakeββΌPfakeββ[log(1βΟfakeβ)]
where:
- Οrealβ=Ο(C(xrealβ)βExfakeββΌPfakeββ[C(xfakeβ)])
- Οfakeβ=Ο(C(xfakeβ)βExrealββΌPrealββ[C(xrealβ)])
Here, ExfakeββΌPfakeββ[C(xfakeβ)] is the average discriminator output for fake samples in the batch, and ExrealββΌPrealββ[C(xrealβ)] is the average discriminator output for real samples in the batch. The discriminator is learning to make C(xrealβ) larger than the average C(xfakeβ), and C(xfakeβ) smaller than the average C(xrealβ).
The generator G is trained to minimize the opposite objective:
LGRaSGANβ=βExfakeββΌPfakeββ[log(Οfakeβ)]βExrealββΌPrealββ[log(1βΟrealβ)]
Notice the symmetry. The generator benefits both from increasing the perceived realism of its generated samples relative to the average real sample (Οfakeβ) and decreasing the perceived realism of real samples relative to the average fake sample (1βΟrealβ). This structure provides gradients to the generator based on both real and fake samples, which can lead to more stable learning.
Benefits of Relativistic GANs
- Improved Stability: By incorporating comparisons between real and fake batches directly into the loss, RaGAN often leads to more stable training dynamics compared to the standard GAN objective, reducing issues like mode collapse.
- Faster Convergence: Empirical results suggest that RaGAN can converge faster than standard GANs and sometimes even WGAN-GP.
- Higher Sample Quality: The relative comparison can guide the generator more effectively, potentially leading to generated samples of higher visual fidelity.
Implementation Approaches
Implementing RaGAN involves modifying the loss calculation:
- Compute the discriminator outputs C(xrealβ) for the real batch and C(xfakeβ) for the fake batch.
- Calculate the average of these outputs across their respective batches: \text{avg_real} = \text{mean}(C(x_{real})) and \text{avg_fake} = \text{mean}(C(x_{fake})).
- Compute the relativistic differences: C(x_{real}) - \text{avg_fake} and C(x_{fake}) - \text{avg_real}.
- Apply the sigmoid function and calculate the binary cross-entropy loss based on the RaSGAN formulas above for both the discriminator and generator updates.
Relativistic GANs, particularly RaGAN, provide a different approach to GAN training. By shifting the discriminator's task from absolute to relative realism assessment, they offer a practical method for achieving more stable and effective training, adding another valuable technique to your toolkit for building advanced generative models. While techniques like WGAN-GP or Spectral Normalization address stability through distance metrics or regularization, RaGAN modifies the fundamental objective of the discriminator-generator game itself.