Basics of Generative Adversarial Networks (GANs) (original) (raw)
Last Updated : 15 Jun, 2026
Generative Adversarial Networks (GANs) are a deep learning technique used in generative modeling to learn patterns from existing data and create new, similar samples. They achieve this through a competitive training process involving two neural networks that improve each other over time.
- Consists of a Generator and a Discriminator that are trained simultaneously in an adversarial manner.
- Capable of generating realistic synthetic data such as images, videos, and audio from random noise.
Key Components
Generative Adversarial Networks (GANs) consist of two main components that work together in a competitive manner:
- **Generator: Creates new data by learning patterns from the training dataset. For example, it can generate realistic images from random noise that resemble real-world objects, animals, or landscapes.
- **Discriminator: Evaluates the data produced by the Generator by comparing it with real data and classifying it as either real or fake. This feedback helps the Generator improve its outputs over time.
Example
The Generator generates some random images (eg. tables) and then the discriminator compares those images with some real world table images and sends the feedback to itself and Generator, helping the Generator create better, more realistic images over time. Let's see GAN structure below.
**Working of GAN

GAN structure
**Step 1: Training the Discriminator
**1. Initial Generator Output: The Generator creates random images from noise. Initially, these images do not resemble real dogs.
**2. Discriminator Input: The Discriminator is shown two sets of images:
- Generated images from the Generator.
- Real images from the dataset (in this case, actual dog images).
**3. Discriminator’s Evaluation: The Discriminator assigns a probability to each image, indicating how likely it is to be real.
- Generated images may receive probabilities like 0.8, 0.3, and 0.5.
- Real dog images may receive probabilities like 0.1, 0.9, and 0.2.
**4. Loss Calculation: The Discriminator aims to label real images as **1 and generated images as **0. The loss is calculated by comparing the predicted probabilities with the correct values.
- If a generated image receives a probability of 0.8, the loss is 0 - 0.8 = -0.8.
- If a real image receives a probability of 0.9, the loss is 1 - 0.9 = 0.1.
**5. Backpropagation: After calculating the loss, the Discriminator’s weights are adjusted to improve its ability to distinguish real from fake images.

GAN Step 1
**Step 2: Training the Generator
After the Discriminator is trained, the Generator is updated.
- **Generator Feedback: The Generator receives feedback on how successfully its images fooled the Discriminator.
- **Discriminator Input: The generated images are evaluated again by the Discriminator, which provides new probabilities such as 0.5, 0.1, and 0.2.
- **Error Calculation: The Generator calculates its error by comparing the Discriminator’s output with the desired value of 1 (real).
- **Backpropagation to Generator: Using this feedback, the Generator updates its weights to produce more realistic images over time.
After several iterations, the Generator gradually learns to create images that closely resemble real-world dog images.

GAN Step 2
**Applications
- **Generating Images: GANs can generate images of animals, people, objects or even entire landscapes that look like real photos.
- **Super-Resolution: They can improve the quality of low-resolution images by making them clearer and more detailed.
- **Image Modification: They can change images in creative ways like changing facial expressions or transforming photos into artistic styles.
- **Photo-Realistic Images: They are used to create computer-generated characters or environments for movies, games and virtual reality.
- **Face Aging: It can simulate aging on faces useful for entertainment, security and medical research.
Advantages
- **High-Quality Data Generation: GANs can generate highly realistic data, such as lifelike images, making them useful for computer vision and content creation.
- **Unsupervised Learning: GANs learn patterns from unlabeled data, reducing the need for manual data annotation.
- **Data Augmentation: They can create synthetic data to expand datasets, especially in domains with limited data availability.
- **Creative Applications: GANs are widely used in generating art, music, videos, and other creative content.
- **Improved Data Quality: They can enhance low-resolution images and support image restoration tasks.
Challenges
- **Training Instability: GANs can be difficult to train because the Generator and Discriminator must improve in balance for effective learning.
- **Mode Collapse: The Generator may repeatedly produce similar outputs, reducing the diversity of generated data.
- **Evaluation Metrics: Assessing GAN performance is challenging, as measuring the realism of generated data is not straightforward.