GANs: Deep learning model where two neural networks compete against each other to generate realistic data. (Ian Goodfellow 2014)

The first expectation averages over real examples; the second averages over generated examples obtained by sampling latent noise.
The source labels this displayed objective “conditional” without showing a conditioning variable. The displayed expression is the ordinary GAN objective. The conditional formulation elsewhere in this chapter passes the condition to both the generator and discriminator.
Applications:
- semantic maps to images
- BW images to RGB images,
- Aerial images to maps
- Style transfer
- Image to image transfer (day to night)
- Anomaly detection
- Data Augmentation
- Text to image generation
Converting expectation operator E as integral to understand how GANs work at mathematical level to help us optimize loss functions mathematically.
For a discrete random variable, expectation is a probability-weighted average.
For a continuous random variable, the probability-weighted sum becomes an integral over the probability density.
Optimal discriminator and the GAN objective
Let p_g denote the distribution induced by passing latent samples through G. Rewriting the second expectation over this distribution does not require an invertible generator.
Substituting the optimal discriminator into the objective gives:
The minimum is −log 4 when the generated and data distributions agree; the optimal discriminator then outputs 1/2 wherever their density is positive.
GAN objective: the intermediate steps
For an invertible, differentiable one-dimensional G, a change of variables gives the following density relationship. The absolute Jacobian is required. General neural generators need not be invertible; in that case p_g means the distribution induced by G, and the expectation identity still applies.
For fixed G, maximize the integrand at each x. The derivative rules are d log D/dD=1/D and d log(1−D)/dD=−1/(1−D).
Substitute D* into the generator’s value C(G):
Both KL terms are zero when p_g=p_data. Then M=p_data=p_g, D*=1/2 wherever the density is positive, and the optimum is −log 4. The calculation rewrites expectations over generated samples; it does not require every practical generator to have an inverse.
Mode collapse (aka Helvetica scenario - 2016): generator produces limited diversity in outputs and maps many different latent vectors to the similar x, generator fails to model the full data distribution by learning to exploit the current weakness of discriminator through generating only a few X = G(z) that consistently fools the discriminator.


How to prevent Mode Collapse?
- Minibatch discrimination: The discriminator evaluates image similarity within a minibatch to detect low diversity [1] Real images and generated images are fed to the discriminator in separate batches. e.g. a batch of 64 real images, and a batch of 64 fake images. [2] For each image x in a batch, compute a similarity measure o(x) to other images in the same batch. [3] similarity score o(x) is appended as additional features in one of the dense layers of the discriminator. [4] If mode collapse happens similarity scores o(x) will be high, discriminator will begin penalizing batches with low diversity
- Unrolled GANs: Prevents the generator from overfitting to the current discriminator by simulating how the discriminator will react after k future training steps; this "look-ahead" training encourages the generator to generalize better and avoid exploiting a temporarily weak discriminator
- Experience Replay: Maintains a buffer of past generated samples and reintroduces them during training, which prevents the discriminator from forgetting old mistakes and forces the generator to stay diverse in order to avoid being penalized by its own historical weaknesses.
- Modified Training Objectives: Replaces standard GAN losses (like binary cross-entropy) with alternatives like Wasserstein loss (for smoother gradients and stable convergence) or Least Squares loss (to avoid vanishing gradients and sharp discriminator boundaries), producing more reliable training signals and reducing collapse.
- Regularization: Adds controlled noise to the training process through techniques like label smoothing (e.g., real = 0.9), input noise (Gaussian), or dropout in the discriminator, weakening the discriminator’s overconfidence and encouraging the generator to diversify its outputs.
- Architecture Tweaks: Enhances the model capacity and expressiveness by adding deeper networks, residual/attention mechanisms, better activations (e.g., LeakyReLU), or using progressive growing (as in ProGAN), allowing the generator to explore a broader space of outputs and reduce mode collapse.
- Feature Matching: Trains the generator to match statistics (like means or covariances) of intermediate features from real data inside the discriminator, encouraging the generator to create data that not only fools the discriminator but also aligns with real-data distributions, boosting realism and diversity.
- Penalizing the Discriminator: Introduces penalties (e.g., gradient penalties like R1, WGAN-GP, DRAGAN, or confidence penalties) to limit the discriminator's confidence and overfitting, ensuring it provides meaningful gradients to the generator and avoids overpowering it.
- Two time-scale update rule (TTUR): use separate learning rates for the generator and discriminator to balance their training dynamics.
- Ensemble of Discriminators: Employs multiple discriminators, each seeing different data subsets or perspectives, requiring the generator to generalize across all of them and preventing it from overfitting to a single discriminator's feedback, thus promoting robustness and diversity.
- Latent space Regularization: Encourages the generator to produce significantly different outputs for different latent inputs by penalizing similar outputs from distinct latent vectors, ensuring that it meaningfully utilizes the input noise and avoids collapsing to a few output modes.
Conditional GANs: Conditional GANs solve this by allowing the user to specify the class label, making the generation process controlled and targeted. Traditional GANs don’t have control over the class of generated data. Training data includes one hot vectors for each class label.

In the inference phase, the user choose the desired class label and the generator generates a new point from that class.