Generative Magic: GANs 101

Miray TOPAL
4 min readJul 14, 2023

--

Welcome to the first article in my series of articles on GANs! In this series, I aim to explore the exciting world of Generative Adversarial Networks (GANs). GANs have emerged as powerful machine learning models capable of generating realistic and high-quality synthetic data, revolutionizing various fields such as art, gaming, and data augmentation. Join me on this exciting journey to understand how GANs work and discover their potential. So let’s dive in without wasting any time!

We will talk about when we should prefer GANs in the next articles, but first I would like to talk about how it works. Let’s start with an example to better understand the working principle of GANs.

Do you remember the thrilling chase in the movie “Catch Me if You Can”? In the world of GANs, just like the relentless pursuit of Frank Abagnale Jr., the discriminator tirelessly distinguishes between real and fake images, while the generator utilizes its creative abilities to craft convincing forgeries. As the training progresses, the generator improves its ability to generate realistic data, and the discriminator becomes more accurate in distinguishing between real and fake data. This dynamic interplay between the two components results in the generation of realistic and captivating images, reminiscent of the captivating tale of “Catch Me if You Can.”

Figure 1: GAN Structure

The example explains a lot about GANs, but we’ll dive into some more technical details together.

GAN and Discriminator Architecture:

At the core of GANs lies a neural network called the generator, which generates synthetic data by processing random noise. This data is then combined with real data and fed into another neural network known as the discriminator. The discriminator’s primary objective is to differentiate between real and fake data, thereby acting as a binary classifier.

Adversarial Learning:

GAN training involves two networks with opposite goals. The generator aims to create fake data that is realistic enough to deceive the discriminator, while the discriminator strives to become proficient at distinguishing real from fake data. This adversarial dynamic drives the improvement of both networks over time.

The Generator’s Learning Process:

The interesting thing about this network is that the generator never sees the actual images, it only sees the noise. Instead, it learns from the gradients that propagate back from the discriminator. As the discriminator becomes more adept at differentiating real and fake data, the knowledge flowing back to the generator improves. Consequently, the generator enhances its ability to produce more convincing fake data, ultimately improving its generative capabilities.

Figure 2: Backpropagation in generator training (source)

The Discriminator’s Learning Process and Training Loop:

GANs employ a unique training loop that involves two distinct phases. In the initial phase, the discriminator is independently trained using batches of labeled real and fake data. The discriminator’s parameters are updated to enhance its classification performance. In the subsequent phase, the generator is trained by generating a batch of fake images while attempting to fool the discriminator into labeling them as real. Although the discriminator’s parameters are frozen during this step, its judgments regarding the authenticity of the data are conveyed back to the generator, enabling it to optimize its generation process.

Figure 3: Backpropagation in discriminator training

Synergistic Improvement:

The iterative training process of GANs allows the generator and discriminator to mutually reinforce each other. As the discriminator becomes more discerning, it provides stronger feedback to the generator, prompting the generation of higher-quality fake data. Simultaneously, the generator’s improved performance challenges the discriminator to enhance its discriminative capabilities. This collaborative interplay between the networks fosters continuous growth and refinement.

We are familiar with the ending of the movie ‘Catch Me if You Can.’ Just like the story of Frank Abagnale Jr. and Carl Hanratty, the generator and discriminator in GANs may appear to be in competition, but they actually rely on each other to thrive. The generator needs to evolve in order to surpass the discriminator’s ability to test for realism, while the discriminator contributes to the development of the generator by accurately distinguishing between real and fake data. This symbiotic relationship ensures the successful operation of GANs, making them inseparable and interconnected entities.

Thank you for reading this article. I appreciate your time. See you soon! :)

You can follow me on Github: https://github.com/miraytopal

Application of GANs:

--

--