What is GAN? Generative Adversarial Networks Explained

Written by Jessica Schulze • Updated on

Learn how GANs work, what they’re used for, and explore examples in this beginner-friendly guide.

[Featured Image] A machine learning engineer in a gray shirt sits with his back to his desk and speaks with co-workers.

A machine learning model is a file that can recognize patterns in information. These models are trained on a set of data, guided by instructions called a machine learning algorithm. Machine learning models can be used to automate repetitive decision-making processes, sort information, create new data samples, and make predictions. 

For example, suppose you want to train a home security camera to recognize certain people. You could provide the model with pictures of your family, labeling them as non-threatening. A machine learning algorithm can instruct the camera to withhold security alerts when it detects anyone in the non-threatening data set. Now, instead of receiving security alerts for every movement detected, you’ll only receive security alerts for motion detection caused by people outside your family. 

What is GAN?  

GAN stands for Generative Adversarial Network. It’s a type of machine learning model called a neural network, specially designed to imitate the structure and function of a human brain. For this reason, neural networks in machine learning are sometimes referred to as artificial neural networks (ANNs). This technology is the basis of deep learning, a subcategory of machine learning (ML) capable of recognizing complex patterns in varying data types such as images, sounds, and text. 

Human neurons vs. artificial neurons

Neurons in your brain are cells that use chemicals and electrical signals to send information between different parts of your brain and body. Neurons in machine learning models are modules of software that send information and computations to one another. 


Generative models

Generative models can generate new data samples by interpreting how data is placed in addition to what the data represents. In contrast, discriminative models focus on differentiating between existing data samples. 

Generative vs. discriminative models

Suppose you provided this line of characters to a discriminative model and a generative model: 

^  ⌄ ^  ⌄ ^  ⌄

A generative model can predict how likely it is for a downward arrow to appear next in line. A discriminative model can decide which symbols are upward-facing and which are downward-facing. While the generative model also recognizes which arrows are facing in which direction, it takes its analysis further by assigning a probability to a sequence of symbols. Discriminative models instead focus on how likely the labels “upward” and “downward” are to apply to each symbol.


Neural networks

Generative models are made up of two types of neural networks:

  1. Generator. Generators are convolutional neural networks (CNN), a type of deep learning algorithm that can process an input image, differentiate between the objects within it, and assign importance to each one. These degrees of importance are known as weights. A generator network aims to create outputs that could be mistaken for real data. 

  2. Discriminator. Discriminators are deconvolutional neural networks (DNN). These algorithms work in reverse to CNNs, aiming to identify the features of an input that were either missed by the CNN or convoluted with other signals. A discriminator network aims to identify which received output is artificial.

Adversarial setting

In the context of GANs, adversarial describes the training environment for each neural network (DNN and CNN). During training, the generator and discriminator networks compete with one another in a bluffing game. The generator creates artificial data samples, such as fake images, to trick the discriminator into accepting them as authentic. In response, the discriminator attempts to identify which data samples are real images and which are not. They practice this game over and over, each one improving at their role each time. 

Types of GANs

Researchers are still identifying new use cases for GANs and improving upon existing GAN techniques. Here are a couple of examples of different types of GANs:

  • CycleGAN. Cycle generative adversarial networks focus on image-to-image translations. Training data consists of two unpaired data sets or groups of images with no labels or correspondences. The CycleGAN uses this information to learn how to transform images from one set into images that could pass for belonging to the other set. For example, suppose you provided a CycleGAN with two sets of images: one depicting house cats and one depicting tigers. The output image might look like a house cat with tiger stripes. Or, the inverse might depict a house-cat-sized tiger.

  • Super-resolution GANs. SRGANs are trained to increase image resolution by filling details into blurry areas of an image. They accomplish this using perceptual loss function, a technique that measures the difference between the high-level perceptual features of two images.

Pros and cons of GANs

Advantages of GANsDisadvantages of GANs
GANs are considered unsupervised learning models, continuing to train themselves after the initial input and capable of learning from unlabeled data.They can be difficult to train due to the need for large, varied, and advanced data sets.
GANs are capable of identifying anomalies based on measurements that indicate how well the generator and discriminator are able to model the data.It can be challenging to evaluate results depending on the complexity of a given task.
Ability to create realistic data samplesGANs suffer from mode collapse, or learning to produce only one output due to its high plausibility and ability to trick the discriminator.

Learn more about GANs with Coursera

If you’re new to machine learning, consider getting started with a beginner-friendly online course. You can learn to build and train machine learning models in just two months with the Machine Learning Specialization offered by Stanford University and DeepLearning.AI. If you’re already familiar with machine learning models and want to learn more about GANs, you might prefer an intermediate-level program like the Generative Adversarial Networks (GANs) Specialization offered by DeepLearning.AI. You’ll build a better understanding of GAN components, compare generative models, and build your own basic GANs using PyTorch. 

Keep reading

Updated on
Written by:


Jessica is a technical writer who specializes in computer science and information technology. Equipp...

This content has been made available for informational purposes only. Learners are advised to conduct additional research to ensure that courses and other credentials pursued meet their personal, professional, and financial goals.