What’s generative adversarial networks (GANs) ?
Table of content
In this content, you will discover the functioning of a generative adversarial networks used in the domain of artificial intelligence. This kind of technology can be used by designer, engineer or architect and so on.
- Generative adversarial networks
- GANs
- Machine Learning
- Deep Learning
- Artificial Intelligence (AI)
- Yasar, K., & Lewis, S. (2023). Generative Adversarial Network (GAN). Enterprise AI.
- Présentation de la structure du GAN. (s. d.). Google for Developers.
- GeeksforGeeks. (2023). Generative Adversarial Network GAN. GeeksforGeeks.
- Agrawal, R. (2023). An End-to-End Introduction to Generative Adversarial Networks(GANs). Analytics Vidhya.
- Generative Adversarial Networks and Plan Stylistic Plan Generation — Computational Architecture Research Lab. (s. d.). Computational Architecture Research Lab.
enerative Adversarial Networks (GANs) constitute a transformative class of neural networks focused on generating synthetic data that mirrors the original input. Composing a dynamic interplay between the discriminator and the generator, GANs excel in creating realistic outputs, illustrated by examples like lifelike dog images. This brief introduction sets the stage for exploring the structural components, mathematical intricacies, and practical applications that define the innovative landscape of GANs.
> Generative Adversarial Networks (GANs) _ Illustration
Definition
Generative Adversarial Networks (GANs)
Generative Adversarial Networks (GANs) represent a specific architecture of neural networks. Their primary goal is to generate new synthetic data that closely mimics the original data provided to the algorithm. To accomplish this intricate task, we rely on two key components: the discriminator and the generator. The algorithm's enhancement arises from the competition between the discriminator and the generator. As an illustration, GANs can create images of dogs. The generator produces counterfeit images of dogs, and the discriminator comes into play to assess the authenticity of these images. It plays a crucial role in determining whether the generated images resemble reality. To use a metaphor, this relation can be likened to that of an art professor (discriminator) who tries to distinguish the real Mona Lisa from a false painting by a novice (generator).
GANs are like computer artists using one friend to create dog images and another friend to determine if those images really look like dogs.
Components
Structure of GANs
> Schema of a GANs structure
Discriminator
The function of the discriminator is to evaluate and distinguish between the generator’s output of fake dogs and the training data of real dogs. Indeed, during training, we feed the discriminator with two different data sets: “Real samples” such as real pictures of dogs and “Fake samples” which are images generated by the generator. The discriminator works as a classifier, an algorithm that sorts features (real dogs or fake dogs correspond to 1 or 0). Its output corresponds to the probability of a generated or real image. If the Discriminator makes a mistake in its prediction, for example, if it detects the output image as fake but it’s real, the “Cost function” will indicate a loss score that enhances the discriminator. To sum up, the discriminator gives an evaluation of the generator’s output. The cost function evaluates the discriminator. It permits identifying attributes that contribute to the fake image to improve his detection.
Generator
The function of the generator is to create fake synthetic data improved by the Discriminator’s feedback. The generator tries to produce increasingly realistic samples that fool the discriminator. If the generator forms a faulty output detected by the discriminator (e.g., an unrealistic image of a dog), the “Cost Function” will indicate a loss score that permits improvement of the generator. To sum up, the generator tries to dupe the discriminator. If it fails, the cost function will give him feedback to enhance.
Noise
The starting point of a GAN is the noise vector. We provide the generator with random noise and a set of random values. It permits the generation of a large diversity of output (e.g. random noise can be compared to diverse colors that allow an infinity of tints, the generator is the painter).
The key to improving
Loss function and Cost function
Mathematically
Mathematically, the loss function quantifies the difference between predicted and referential values. For example, in GANs, predicted samples can be fake dogs, referential samples are pictures of dogs and the difference between them is evaluated by the cost value.
However, the peculiarity of GAN is the presence of two cost values (difference) quantified by one cost function (loss function). Each cost value is used to improve the discriminator and the generator separately.
In GANs
• Generator Loss (Cost value 1) :
The generator aims to minimize its associated part of the loss function. This term quantifies how well the generator is able to produce samples that resemble real data, aiming to fool the discriminator. Graphically, the role of the generator is to minimize the distance between the distribution of the real samples and the generated samples.
> Schema : minimize game by the Generator
• Discriminator Loss (Cost value 2) :
The discriminator aims to maximize its associated part of the loss function. This term quantifies how well the discriminator is able to distinguish between real and generated samples. Graphically, the role of the discriminator is to maximize the distance between the distribution of the real samples and the generated samples.
> Schema : maximize game by the Discriminator
• Mini-max problem in GANs :
The overall cost function is a combination of these two components. The training process involves a dynamic interplay where, during each iteration, the generator and discriminator are updated based on their respective losses (cost values). The competition between the generator and the discriminator, driven by the shared cost function, leads to the refinement of both networks.
To sum up, in GANs, the loss function is used by the Cost function, which gives two feedbacks to improve the generator and the discriminator.
Informaticaly
Parameters:
gen: the generator model, which returns an image given z-dimensional noise
disc: the discriminator model, which returns a single-dimensional prediction of real/fake
criterion: the loss function, which should be used to compare the discriminator's predictions to the ground truth (real sample) (e.g. fake = 0, real = 1)
criterion = nn.BCEWithLogitsLoss()
#BCEWithLogitsLoss or Binary Cross Entropy Loss: It measures the divergence between real and predicted probability distributions in the case of binary classification.
#For each example, it gauges how well the predictions align with the true labels.”
#DISCRIMINATOR LOSS :
def get_disc_loss(gen, disc, criterion, real, num_images, z_dim, device):
#1. Get the discriminator's prediction of fake images
disc_fake_pred = disc(fake.detach())
#2. Calculate the loss of the evaluation of fake images by the discriminator
disc_fake_loss = criterion(disc_fake_pred, torch.zeros_like(disc_fake_pred))
#3. Get the discriminator's prediction of real images
disc_real_pred = disc(real)
#4. Calculate the loss of the evaluation of real images by the discriminator
disc_real_loss = criterion(disc_real_pred, torch.ones_like(disc_real_pred))
#5. Calculate the discriminator's loss by averaging the real and fake loss
disc_loss = (disc_fake_loss + disc_real_loss) / 2
return disc_loss
#GENERATOR LOSS :
def get_gen_loss(gen, disc, criterion, num_images, z_dim, device):
#1. Get the discriminator's prediction of the fake image.
disc_fake_pred = disc(fake)
#2. Calculate the generator's loss, the generator wants to fool the discriminator prediction. gen_loss = criterion(disc_fake_pred, torch.ones_like(disc_fake_pred))
return gen_loss
> Project MNIST Data Handwritten, result of two cost values
With the utilization of a GAN in this project, the objective was to generate simulated handwritten numbers. In the illustration below, it's evident that the algorithm improves as the cost value of the Generator increases and the cost value of the Discriminator decreases.
Examples
Applications
Image to image
> GANHouse by HDR Data driven design
Pix2Pix is based on cGAN. The goal of Pix2Pix is to convert “structured data '' (e.g., drawing a house) into a new synthetic based on the path of the structured data (e.g., a picture of a house based on the drawing outline).
These types of AI are composed of two different convolutional neural networks :
• U-Net : It permits segmenting different parts of the image (door’s pixels, window's pixels)
• PathGAN : it produces a prediction map (input : drawing door corresponds to the output: wooden door, the prediction). The main difference between GAN and PathGAN is that the latter uses “structured input”, for example, the outlines of a door.
Text to video
> Google’s research paper, Imagen Video
Prompt : "I want an astraunote riding on a horse"
The aim is to generate a video based on textual order. Different types of algorithms are used, such as natural language processing and computer vision (GANs).
Based on the input of realistic 2D pictures, the GAN aims to synthesize realistic 3D models (e.g., a three-dimensional mushroom).
Image to 3D generation
> Inverse Graphics GAN :
Sebastian Lunz / Yingzhen Li / Andrew Fitzgibbon / Nate Kushman
Based on the input of realistic 2D pictures, the GAN aims to synthesize realistic 3D models (e.g., a three-dimensional mushroom).
Summary
Definition of GANs
GANs, or Generative Adversarial Networks, redefine data generation by mimicking the input with synthetic precision.
Components
• Discriminator: Sorts features, distinguishing between real and fake data.
• Generator: Creates diverse synthetic data, refining output through feedback.
• Noise: Initiates diversity in generated outputs
Key to Improvement : Loss Function and Cost Function
• Generator Loss: Minimizes the difference to fool the discriminator.
• Discriminator Loss: Maximizes the difference to enhance discrimination.
• Mini-max Game in GANs: Drives dynamic refinement between generator and discriminator.
Applications
• Image to Image: Illustrated by Pix2Pix, transforming structured data into synthetic images.
•Text to Video: Utilizing natural language processing and computer vision for video generation.
• Image to 3D Generation: Synthesizing realistic 3D models from 2D pictures.
Author
Rémi Tvl.
" Embarking on my academic journey at the National school of Architecture in Paris, I've cultivated a profound enthusiasm for pushing the boundaries of innovative architectural design, with a special focus on AI. "







