Shortcuts

DCGAN Tutorial

Author: Nathan Inkawhich

Introduction

This tutorial will give an introduction to DCGANs through an example. We will train a generative adversarial network (GAN) to generate new celebrities after showing it pictures of many real celebrities. Most of the code here is from the DCGAN implementation in pytorch/examples, and this document will give a thorough explanation of the implementation and shed light on how and why this model works. But don’t worry, no prior knowledge of GANs is required, but it may require a first-timer to spend some time reasoning about what is actually happening under the hood. Also, for the sake of time it will help to have a GPU, or two. Lets start from the beginning.

Generative Adversarial Networks

What is a GAN?

GANs are a framework for teaching a deep learning model to capture the training data distribution so we can generate new data from that same distribution. GANs were invented by Ian Goodfellow in 2014 and first described in the paper Generative Adversarial Nets. They are made of two distinct models, a generator and a discriminator. The job of the generator is to spawn ‘fake’ images that look like the training images. The job of the discriminator is to look at an image and output whether or not it is a real training image or a fake image from the generator. During training, the generator is constantly trying to outsmart the discriminator by generating better and better fakes, while the discriminator is working to become a better detective and correctly classify the real and fake images. The equilibrium of this game is when the generator is generating perfect fakes that look as if they came directly from the training data, and the discriminator is left to always guess at 50% confidence that the generator output is real or fake.

Now, lets define some notation to be used throughout tutorial starting with the discriminator. Let \(x\) be data representing an image. \(D(x)\) is the discriminator network which outputs the (scalar) probability that \(x\) came from training data rather than the generator. Here, since we are dealing with images, the input to \(D(x)\) is an image of CHW size 3x64x64. Intuitively, \(D(x)\) should be HIGH when \(x\) comes from training data and LOW when \(x\) comes from the generator. \(D(x)\) can also be thought of as a traditional binary classifier.

For the generator’s notation, let \(z\) be a latent space vector sampled from a standard normal distribution. \(G(z)\) represents the generator function which maps the latent vector \(z\) to data-space. The goal of \(G\) is to estimate the distribution that the training data comes from (\(p_{data}\)) so it can generate fake samples from that estimated distribution (\(p_g\)).

So, \(D(G(z))\) is the probability (scalar) that the output of the generator \(G\) is a real image. As described in Goodfellow’s paper, \(D\) and \(G\) play a minimax game in which \(D\) tries to maximize the probability it correctly classifies reals and fakes (\(logD(x)\)), and \(G\) tries to minimize the probability that \(D\) will predict its outputs are fake (\(log(1-D(G(z)))\)). From the paper, the GAN loss function is

\[\underset{G}{\text{min}} \underset{D}{\text{max}}V(D,G) = \mathbb{E}_{x\sim p_{data}(x)}\big[logD(x)\big] + \mathbb{E}_{z\sim p_{z}(z)}\big[log(1-D(G(z)))\big] \]

In theory, the solution to this minimax game is where \(p_g = p_{data}\), and the discriminator guesses randomly if the inputs are real or fake. However, the convergence theory of GANs is still being actively researched and in reality models do not always train to this point.

What is a DCGAN?

A DCGAN is a direct extension of the GAN described above, except that it explicitly uses convolutional and convolutional-transpose layers in the discriminator and generator, respectively. It was first described by Radford et. al. in the paper Unsupervised Representation Learning With Deep Convolutional Generative Adversarial Networks. The discriminator is made up of strided convolution layers, batch norm layers, and LeakyReLU activations. The input is a 3x64x64 input image and the output is a scalar probability that the input is from the real data distribution. The generator is comprised of convolutional-transpose layers, batch norm layers, and ReLU activations. The input is a latent vector, \(z\), that is drawn from a standard normal distribution and the output is a 3x64x64 RGB image. The strided conv-transpose layers allow the latent vector to be transformed into a volume with the same shape as an image. In the paper, the authors also give some tips about how to setup the optimizers, how to calculate the loss functions, and how to initialize the model weights, all of which will be explained in the coming sections.

#%matplotlib inline
import argparse
import os
import random
import torch
import torch.nn as nn
import torch.nn.parallel
import torch.optim as optim
import torch.utils.data
import torchvision.datasets as dset
import torchvision.transforms as transforms
import torchvision.utils as vutils
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from IPython.display import HTML

# Set random seed for reproducibility
manualSeed = 999
#manualSeed = random.randint(1, 10000) # use if you want new results
print("Random Seed: ", manualSeed)
random.seed(manualSeed)
torch.manual_seed(manualSeed)
torch.use_deterministic_algorithms(True) # Needed for reproducible results
Random Seed:  999

Inputs

Let’s define some inputs for the run:

  • dataroot - the path to the root of the dataset folder. We will talk more about the dataset in the next section.

  • workers - the number of worker threads for loading the data with the DataLoader.

  • batch_size - the batch size used in training. The DCGAN paper uses a batch size of 128.

  • image_size - the spatial size of the images used for training. This implementation defaults to 64x64. If another size is desired, the structures of D and G must be changed. See here for more details.

  • nc - number of color channels in the input images. For color images this is 3.

  • nz - length of latent vector.

  • ngf - relates to the depth of feature maps carried through the generator.

  • ndf - sets the depth of feature maps propagated through the discriminator.

  • num_epochs - number of training epochs to run. Training for longer will probably lead to better results but will also take much longer.

  • lr - learning rate for training. As described in the DCGAN paper, this number should be 0.0002.

  • beta1 - beta1 hyperparameter for Adam optimizers. As described in paper, this number should be 0.5.

  • ngpu - number of GPUs available. If this is 0, code will run in CPU mode. If this number is greater than 0 it will run on that number of GPUs.

# Root directory for dataset
dataroot = "data/celeba"

# Number of workers for dataloader
workers = 2

# Batch size during training
batch_size = 128

# Spatial size of training images. All images will be resized to this
#   size using a transformer.
image_size = 64

# Number of channels in the training images. For color images this is 3
nc = 3

# Size of z latent vector (i.e. size of generator input)
nz = 100

# Size of feature maps in generator
ngf = 64

# Size of feature maps in discriminator
ndf = 64

# Number of training epochs
num_epochs = 5

# Learning rate for optimizers
lr = 0.0002

# Beta1 hyperparameter for Adam optimizers
beta1 = 0.5

# Number of GPUs available. Use 0 for CPU mode.
ngpu = 1

Data

In this tutorial we will use the Celeb-A Faces dataset which can be downloaded at the linked site, or in Google Drive. The dataset will download as a file named img_align_celeba.zip. Once downloaded, create a directory named celeba and extract the zip file into that directory. Then, set the dataroot input for this notebook to the celeba directory you just created. The resulting directory structure should be:

/path/to/celeba
    -> img_align_celeba
        -> 188242.jpg
        -> 173822.jpg
        -> 284702.jpg
        -> 537394.jpg
           ...

This is an important step because we will be using the ImageFolder dataset class, which requires there to be subdirectories in the dataset root folder. Now, we can create the dataset, create the dataloader, set the device to run on, and finally visualize some of the training data.

# We can use an image folder dataset the way we have it setup.
# Create the dataset
dataset = dset.ImageFolder(root=dataroot,
                           transform=transforms.Compose([
                               transforms.Resize(image_size),
                               transforms.CenterCrop(image_size),
                               transforms.ToTensor(),
                               transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5)),
                           ]))
# Create the dataloader
dataloader = torch.utils.data.DataLoader(dataset, batch_size=batch_size,
                                         shuffle=True, num_workers=workers)

# Decide which device we want to run on
device = torch.device("cuda:0" if (torch.cuda.is_available() and ngpu > 0) else "cpu")

# Plot some training images
real_batch = next(iter(dataloader))
plt.figure(figsize=(8,8))
plt.axis("off")
plt.title("Training Images")
plt.imshow(np.transpose(vutils.make_grid(real_batch[0].to(device)[:64], padding=2, normalize=True).cpu(),(1,2,0)))
Training Images
<matplotlib.image.AxesImage object at 0x7f1e01e180d0>

Implementation

With our input parameters set and the dataset prepared, we can now get into the implementation. We will start with the weight initialization strategy, then talk about the generator, discriminator, loss functions, and training loop in detail.

Weight Initialization

From the DCGAN paper, the authors specify that all model weights shall be randomly initialized from a Normal distribution with mean=0, stdev=0.02. The weights_init function takes an initialized model as input and reinitializes all convolutional, convolutional-transpose, and batch normalization layers to meet this criteria. This function is applied to the models immediately after initialization.

# custom weights initialization called on ``netG`` and ``netD``
def weights_init(m):
    classname = m.__class__.__name__
    if classname.find('Conv') != -1:
        nn.init.normal_(m.weight.data, 0.0, 0.02)
    elif classname.find('BatchNorm') != -1:
        nn.init.normal_(m.weight.data, 1.0, 0.02)
        nn.init.constant_(m.bias.data, 0)

Generator

The generator, \(G\), is designed to map the latent space vector (\(z\)) to data-space. Since our data are images, converting \(z\) to data-space means ultimately creating a RGB image with the same size as the training images (i.e. 3x64x64). In practice, this is accomplished through a series of strided two dimensional convolutional transpose layers, each paired with a 2d batch norm layer and a relu activation. The output of the generator is fed through a tanh function to return it to the input data range of \([-1,1]\). It is worth noting the existence of the batch norm functions after the conv-transpose layers, as this is a critical contribution of the DCGAN paper. These layers help with the flow of gradients during training. An image of the generator from the DCGAN paper is shown below.

dcgan_generator

Notice, how the inputs we set in the input section (nz, ngf, and nc) influence the generator architecture in code. nz is the length of the z input vector, ngf relates to the size of the feature maps that are propagated through the generator, and nc is the number of channels in the output image (set to 3 for RGB images). Below is the code for the generator.

# Generator Code

class Generator(nn.Module):
    def __init__(self, ngpu):
        super(Generator, self).__init__()
        self.ngpu = ngpu
        self.main = nn.Sequential(
            # input is Z, going into a convolution
            nn.ConvTranspose2d( nz, ngf * 8, 4, 1, 0, bias=False),
            nn.BatchNorm2d(ngf * 8),
            nn.ReLU(True),
            # state size. ``(ngf*8) x 4 x 4``
            nn.ConvTranspose2d(ngf * 8, ngf * 4, 4, 2, 1, bias=False),
            nn.BatchNorm2d(ngf * 4),
            nn.ReLU(True),
            # state size. ``(ngf*4) x 8 x 8``
            nn.ConvTranspose2d( ngf * 4, ngf * 2, 4, 2, 1, bias=False),
            nn.BatchNorm2d(ngf * 2),
            nn.ReLU(True),
            # state size. ``(ngf*2) x 16 x 16``
            nn.ConvTranspose2d( ngf * 2, ngf, 4, 2, 1, bias=False),
            nn.BatchNorm2d(ngf),
            nn.ReLU(True),
            # state size. ``(ngf) x 32 x 32``
            nn.ConvTranspose2d( ngf, nc, 4, 2, 1, bias=False),
            nn.Tanh()
            # state size. ``(nc) x 64 x 64``
        )

    def forward(self, input):
        return self.main(input)

Now, we can instantiate the generator and apply the weights_init function. Check out the printed model to see how the generator object is structured.

# Create the generator
netG = Generator(ngpu).to(device)

# Handle multi-GPU if desired
if (device.type == 'cuda') and (ngpu > 1):
    netG = nn.DataParallel(netG, list(range(ngpu)))

# Apply the ``weights_init`` function to randomly initialize all weights
#  to ``mean=0``, ``stdev=0.02``.
netG.apply(weights_init)

# Print the model
print(netG)
Generator(
  (main): Sequential(
    (0): ConvTranspose2d(100, 512, kernel_size=(4, 4), stride=(1, 1), bias=False)
    (1): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
    (2): ReLU(inplace=True)
    (3): ConvTranspose2d(512, 256, kernel_size=(4, 4), stride=(2, 2), padding=(1, 1), bias=False)
    (4): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
    (5): ReLU(inplace=True)
    (6): ConvTranspose2d(256, 128, kernel_size=(4, 4), stride=(2, 2), padding=(1, 1), bias=False)
    (7): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
    (8): ReLU(inplace=True)
    (9): ConvTranspose2d(128, 64, kernel_size=(4, 4), stride=(2, 2), padding=(1, 1), bias=False)
    (10): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
    (11): ReLU(inplace=True)
    (12): ConvTranspose2d(64, 3, kernel_size=(4, 4), stride=(2, 2), padding=(1, 1), bias=False)
    (13): Tanh()
  )
)

Discriminator

As mentioned, the discriminator, \(D\), is a binary classification network that takes an image as input and outputs a scalar probability that the input image is real (as opposed to fake). Here, \(D\) takes a 3x64x64 input image, processes it through a series of Conv2d, BatchNorm2d, and LeakyReLU layers, and outputs the final probability through a Sigmoid activation function. This architecture can be extended with more layers if necessary for the problem, but there is significance to the use of the strided convolution, BatchNorm, and LeakyReLUs. The DCGAN paper mentions it is a good practice to use strided convolution rather than pooling to downsample because it lets the network learn its own pooling function. Also batch norm and leaky relu functions promote healthy gradient flow which is critical for the learning process of both \(G\) and \(D\).

Discriminator Code

class Discriminator(nn.Module):
    def __init__(self, ngpu):
        super(Discriminator, self).__init__()
        self.ngpu = ngpu
        self.main = nn.Sequential(
            # input is ``(nc) x 64 x 64``
            nn.Conv2d(nc, ndf, 4, 2, 1, bias=False),
            nn.LeakyReLU(0.2, inplace=True),
            # state size. ``(ndf) x 32 x 32``
            nn.Conv2d(ndf, ndf * 2, 4, 2, 1, bias=False),
            nn.BatchNorm2d(ndf * 2),
            nn.LeakyReLU(0.2, inplace=True),
            # state size. ``(ndf*2) x 16 x 16``
            nn.Conv2d(ndf * 2, ndf * 4, 4, 2, 1, bias=False),
            nn.BatchNorm2d(ndf * 4),
            nn.LeakyReLU(0.2, inplace=True),
            # state size. ``(ndf*4) x 8 x 8``
            nn.Conv2d(ndf * 4, ndf * 8, 4, 2, 1, bias=False),
            nn.BatchNorm2d(ndf * 8),
            nn.LeakyReLU(0.2, inplace=True),
            # state size. ``(ndf*8) x 4 x 4``
            nn.Conv2d(ndf * 8, 1, 4, 1, 0, bias=False),
            nn.Sigmoid()
        )

    def forward(self, input):
        return self.main(input)

Now, as with the generator, we can create the discriminator, apply the weights_init function, and print the model’s structure.

# Create the Discriminator
netD = Discriminator(ngpu).to(device)

# Handle multi-GPU if desired
if (device.type == 'cuda') and (ngpu > 1):
    netD = nn.DataParallel(netD, list(range(ngpu)))

# Apply the ``weights_init`` function to randomly initialize all weights
# like this: ``to mean=0, stdev=0.2``.
netD.apply(weights_init)

# Print the model
print(netD)
Discriminator(
  (main): Sequential(
    (0): Conv2d(3, 64, kernel_size=(4, 4), stride=(2, 2), padding=(1, 1), bias=False)
    (1): LeakyReLU(negative_slope=0.2, inplace=True)
    (2): Conv2d(64, 128, kernel_size=(4, 4), stride=(2, 2), padding=(1, 1), bias=False)
    (3): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
    (4): LeakyReLU(negative_slope=0.2, inplace=True)
    (5): Conv2d(128, 256, kernel_size=(4, 4), stride=(2, 2), padding=(1, 1), bias=False)
    (6): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
    (7): LeakyReLU(negative_slope=0.2, inplace=True)
    (8): Conv2d(256, 512, kernel_size=(4, 4), stride=(2, 2), padding=(1, 1), bias=False)
    (9): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
    (10): LeakyReLU(negative_slope=0.2, inplace=True)
    (11): Conv2d(512, 1, kernel_size=(4, 4), stride=(1, 1), bias=False)
    (12): Sigmoid()
  )
)

Loss Functions and Optimizers

With \(D\) and \(G\) setup, we can specify how they learn through the loss functions and optimizers. We will use the Binary Cross Entropy loss (BCELoss) function which is defined in PyTorch as:

\[\ell(x, y) = L = \{l_1,\dots,l_N\}^\top, \quad l_n = - \left[ y_n \cdot \log x_n + (1 - y_n) \cdot \log (1 - x_n) \right] \]

Notice how this function provides the calculation of both log components in the objective function (i.e. \(log(D(x))\) and \(log(1-D(G(z)))\)). We can specify what part of the BCE equation to use with the \(y\) input. This is accomplished in the training loop which is coming up soon, but it is important to understand how we can choose which component we wish to calculate just by changing \(y\) (i.e. GT labels).

Next, we define our real label as 1 and the fake label as 0. These labels will be used when calculating the losses of \(D\) and \(G\), and this is also the convention used in the original GAN paper. Finally, we set up two separate optimizers, one for \(D\) and one for \(G\). As specified in the DCGAN paper, both are Adam optimizers with learning rate 0.0002 and Beta1 = 0.5. For keeping track of the generator’s learning progression, we will generate a fixed batch of latent vectors that are drawn from a Gaussian distribution (i.e. fixed_noise) . In the training loop, we will periodically input this fixed_noise into \(G\), and over the iterations we will see images form out of the noise.

# Initialize the ``BCELoss`` function
criterion = nn.BCELoss()

# Create batch of latent vectors that we will use to visualize
#  the progression of the generator
fixed_noise = torch.randn(64, nz, 1, 1, device=device)

# Establish convention for real and fake labels during training
real_label = 1.
fake_label = 0.

# Setup Adam optimizers for both G and D
optimizerD = optim.Adam(netD.parameters(), lr=lr, betas=(beta1, 0.999))
optimizerG = optim.Adam(netG.parameters(), lr=lr, betas=(beta1, 0.999))

Training

Finally, now that we have all of the parts of the GAN framework defined, we can train it. Be mindful that training GANs is somewhat of an art form, as incorrect hyperparameter settings lead to mode collapse with little explanation of what went wrong. Here, we will closely follow Algorithm 1 from the Goodfellow’s paper, while abiding by some of the best practices shown in ganhacks. Namely, we will “construct different mini-batches for real and fake” images, and also adjust G’s objective function to maximize \(log(D(G(z)))\). Training is split up into two main parts. Part 1 updates the Discriminator and Part 2 updates the Generator.

Part 1 - Train the Discriminator

Recall, the goal of training the discriminator is to maximize the probability of correctly classifying a given input as real or fake. In terms of Goodfellow, we wish to “update the discriminator by ascending its stochastic gradient”. Practically, we want to maximize \(log(D(x)) + log(1-D(G(z)))\). Due to the separate mini-batch suggestion from ganhacks, we will calculate this in two steps. First, we will construct a batch of real samples from the training set, forward pass through \(D\), calculate the loss (\(log(D(x))\)), then calculate the gradients in a backward pass. Secondly, we will construct a batch of fake samples with the current generator, forward pass this batch through \(D\), calculate the loss (\(log(1-D(G(z)))\)), and accumulate the gradients with a backward pass. Now, with the gradients accumulated from both the all-real and all-fake batches, we call a step of the Discriminator’s optimizer.

Part 2 - Train the Generator

As stated in the original paper, we want to train the Generator by minimizing \(log(1-D(G(z)))\) in an effort to generate better fakes. As mentioned, this was shown by Goodfellow to not provide sufficient gradients, especially early in the learning process. As a fix, we instead wish to maximize \(log(D(G(z)))\). In the code we accomplish this by: classifying the Generator output from Part 1 with the Discriminator, computing G’s loss using real labels as GT, computing G’s gradients in a backward pass, and finally updating G’s parameters with an optimizer step. It may seem counter-intuitive to use the real labels as GT labels for the loss function, but this allows us to use the \(log(x)\) part of the BCELoss (rather than the \(log(1-x)\) part) which is exactly what we want.

Finally, we will do some statistic reporting and at the end of each epoch we will push our fixed_noise batch through the generator to visually track the progress of G’s training. The training statistics reported are:

  • Loss_D - discriminator loss calculated as the sum of losses for the all real and all fake batches (\(log(D(x)) + log(1 - D(G(z)))\)).

  • Loss_G - generator loss calculated as \(log(D(G(z)))\)

  • D(x) - the average output (across the batch) of the discriminator for the all real batch. This should start close to 1 then theoretically converge to 0.5 when G gets better. Think about why this is.

  • D(G(z)) - average discriminator outputs for the all fake batch. The first number is before D is updated and the second number is after D is updated. These numbers should start near 0 and converge to 0.5 as G gets better. Think about why this is.

Note: This step might take a while, depending on how many epochs you run and if you removed some data from the dataset.

# Training Loop

# Lists to keep track of progress
img_list = []
G_losses = []
D_losses = []
iters = 0

print("Starting Training Loop...")
# For each epoch
for epoch in range(num_epochs):
    # For each batch in the dataloader
    for i, data in enumerate(dataloader, 0):

        ############################
        # (1) Update D network: maximize log(D(x)) + log(1 - D(G(z)))
        ###########################
        ## Train with all-real batch
        netD.zero_grad()
        # Format batch
        real_cpu = data[0].to(device)
        b_size = real_cpu.size(0)
        label = torch.full((b_size,), real_label, dtype=torch.float, device=device)
        # Forward pass real batch through D
        output = netD(real_cpu).view(-1)
        # Calculate loss on all-real batch
        errD_real = criterion(output, label)
        # Calculate gradients for D in backward pass
        errD_real.backward()
        D_x = output.mean().item()

        ## Train with all-fake batch
        # Generate batch of latent vectors
        noise = torch.randn(b_size, nz, 1, 1, device=device)
        # Generate fake image batch with G
        fake = netG(noise)
        label.fill_(fake_label)
        # Classify all fake batch with D
        output = netD(fake.detach()).view(-1)
        # Calculate D's loss on the all-fake batch
        errD_fake = criterion(output, label)
        # Calculate the gradients for this batch, accumulated (summed) with previous gradients
        errD_fake.backward()
        D_G_z1 = output.mean().item()
        # Compute error of D as sum over the fake and the real batches
        errD = errD_real + errD_fake
        # Update D
        optimizerD.step()

        ############################
        # (2) Update G network: maximize log(D(G(z)))
        ###########################
        netG.zero_grad()
        label.fill_(real_label)  # fake labels are real for generator cost
        # Since we just updated D, perform another forward pass of all-fake batch through D
        output = netD(fake).view(-1)
        # Calculate G's loss based on this output
        errG = criterion(output, label)
        # Calculate gradients for G
        errG.backward()
        D_G_z2 = output.mean().item()
        # Update G
        optimizerG.step()

        # Output training stats
        if i % 50 == 0:
            print('[%d/%d][%d/%d]\tLoss_D: %.4f\tLoss_G: %.4f\tD(x): %.4f\tD(G(z)): %.4f / %.4f'
                  % (epoch, num_epochs, i, len(dataloader),
                     errD.item(), errG.item(), D_x, D_G_z1, D_G_z2))

        # Save Losses for plotting later
        G_losses.append(errG.item())
        D_losses.append(errD.item())

        # Check how the generator is doing by saving G's output on fixed_noise
        if (iters % 500 == 0) or ((epoch == num_epochs-1) and (i == len(dataloader)-1)):
            with torch.no_grad():
                fake = netG(fixed_noise).detach().cpu()
            img_list.append(vutils.make_grid(fake, padding=2, normalize=True))

        iters += 1
Starting Training Loop...
[0/5][0/1583]   Loss_D: 2.0036  Loss_G: 5.6193  D(x): 0.5882    D(G(z)): 0.6680 / 0.0060
[0/5][50/1583]  Loss_D: 0.0044  Loss_G: 32.2117 D(x): 0.9960    D(G(z)): 0.0000 / 0.0000
[0/5][100/1583] Loss_D: 0.0005  Loss_G: 38.9935 D(x): 0.9995    D(G(z)): 0.0000 / 0.0000
[0/5][150/1583] Loss_D: 0.6510  Loss_G: 19.7641 D(x): 0.7788    D(G(z)): 0.0000 / 0.0000
[0/5][200/1583] Loss_D: 0.6251  Loss_G: 4.5788  D(x): 0.7827    D(G(z)): 0.2234 / 0.0200
[0/5][250/1583] Loss_D: 0.6378  Loss_G: 3.3285  D(x): 0.7640    D(G(z)): 0.2024 / 0.0666
[0/5][300/1583] Loss_D: 1.2830  Loss_G: 4.0288  D(x): 0.4212    D(G(z)): 0.0249 / 0.0453
[0/5][350/1583] Loss_D: 0.4362  Loss_G: 3.9802  D(x): 0.8366    D(G(z)): 0.1758 / 0.0260
[0/5][400/1583] Loss_D: 1.0870  Loss_G: 1.4690  D(x): 0.4857    D(G(z)): 0.0776 / 0.2886
[0/5][450/1583] Loss_D: 0.4944  Loss_G: 3.4460  D(x): 0.8479    D(G(z)): 0.2188 / 0.0566
[0/5][500/1583] Loss_D: 0.8039  Loss_G: 4.5647  D(x): 0.7394    D(G(z)): 0.2652 / 0.0194
[0/5][550/1583] Loss_D: 0.3911  Loss_G: 4.8038  D(x): 0.9119    D(G(z)): 0.2311 / 0.0149
[0/5][600/1583] Loss_D: 1.7029  Loss_G: 4.9655  D(x): 0.3406    D(G(z)): 0.0003 / 0.0149
[0/5][650/1583] Loss_D: 0.8950  Loss_G: 3.6007  D(x): 0.8023    D(G(z)): 0.4013 / 0.0543
[0/5][700/1583] Loss_D: 0.5509  Loss_G: 2.8799  D(x): 0.8507    D(G(z)): 0.2291 / 0.1059
[0/5][750/1583] Loss_D: 0.7790  Loss_G: 2.9950  D(x): 0.5906    D(G(z)): 0.0209 / 0.1025
[0/5][800/1583] Loss_D: 0.8846  Loss_G: 5.5525  D(x): 0.8103    D(G(z)): 0.3843 / 0.0078
[0/5][850/1583] Loss_D: 1.1471  Loss_G: 2.5379  D(x): 0.4428    D(G(z)): 0.0162 / 0.1531
[0/5][900/1583] Loss_D: 0.5466  Loss_G: 2.4422  D(x): 0.7483    D(G(z)): 0.1192 / 0.1275
[0/5][950/1583] Loss_D: 1.0247  Loss_G: 3.2335  D(x): 0.5250    D(G(z)): 0.0460 / 0.0806
[0/5][1000/1583]        Loss_D: 0.7944  Loss_G: 5.5772  D(x): 0.8987    D(G(z)): 0.4277 / 0.0076
[0/5][1050/1583]        Loss_D: 0.7378  Loss_G: 2.7377  D(x): 0.5968    D(G(z)): 0.0617 / 0.0910
[0/5][1100/1583]        Loss_D: 0.7739  Loss_G: 3.0808  D(x): 0.6444    D(G(z)): 0.0969 / 0.0814
[0/5][1150/1583]        Loss_D: 0.3946  Loss_G: 3.5747  D(x): 0.8319    D(G(z)): 0.1299 / 0.0473
[0/5][1200/1583]        Loss_D: 0.3434  Loss_G: 3.2099  D(x): 0.8752    D(G(z)): 0.1421 / 0.0678
[0/5][1250/1583]        Loss_D: 0.6460  Loss_G: 3.4157  D(x): 0.7640    D(G(z)): 0.2226 / 0.0537
[0/5][1300/1583]        Loss_D: 0.4382  Loss_G: 4.6277  D(x): 0.9053    D(G(z)): 0.2552 / 0.0161
[0/5][1350/1583]        Loss_D: 1.4234  Loss_G: 2.3097  D(x): 0.3653    D(G(z)): 0.0117 / 0.1792
[0/5][1400/1583]        Loss_D: 0.5761  Loss_G: 3.1358  D(x): 0.7009    D(G(z)): 0.1027 / 0.0777
[0/5][1450/1583]        Loss_D: 1.1262  Loss_G: 1.2970  D(x): 0.4339    D(G(z)): 0.0189 / 0.3399
[0/5][1500/1583]        Loss_D: 0.2875  Loss_G: 4.1165  D(x): 0.8571    D(G(z)): 0.0989 / 0.0267
[0/5][1550/1583]        Loss_D: 1.0144  Loss_G: 3.5034  D(x): 0.8774    D(G(z)): 0.4764 / 0.0549
[1/5][0/1583]   Loss_D: 0.6140  Loss_G: 4.9357  D(x): 0.9112    D(G(z)): 0.3513 / 0.0138
[1/5][50/1583]  Loss_D: 0.5887  Loss_G: 4.8662  D(x): 0.9174    D(G(z)): 0.3425 / 0.0162
[1/5][100/1583] Loss_D: 0.6412  Loss_G: 2.0044  D(x): 0.6471    D(G(z)): 0.0938 / 0.1753
[1/5][150/1583] Loss_D: 1.0779  Loss_G: 5.4925  D(x): 0.9229    D(G(z)): 0.5586 / 0.0109
[1/5][200/1583] Loss_D: 0.9037  Loss_G: 6.8136  D(x): 0.9281    D(G(z)): 0.5013 / 0.0026
[1/5][250/1583] Loss_D: 1.7376  Loss_G: 1.5022  D(x): 0.2971    D(G(z)): 0.0773 / 0.3357
[1/5][300/1583] Loss_D: 0.8750  Loss_G: 5.8249  D(x): 0.9663    D(G(z)): 0.5038 / 0.0055
[1/5][350/1583] Loss_D: 0.3422  Loss_G: 4.1394  D(x): 0.8997    D(G(z)): 0.1851 / 0.0282
[1/5][400/1583] Loss_D: 0.6116  Loss_G: 2.5769  D(x): 0.7088    D(G(z)): 0.1833 / 0.1035
[1/5][450/1583] Loss_D: 0.5114  Loss_G: 4.2154  D(x): 0.8518    D(G(z)): 0.2568 / 0.0221
[1/5][500/1583] Loss_D: 0.5880  Loss_G: 4.2717  D(x): 0.8690    D(G(z)): 0.3113 / 0.0237
[1/5][550/1583] Loss_D: 0.6395  Loss_G: 1.3530  D(x): 0.6273    D(G(z)): 0.0669 / 0.3215
[1/5][600/1583] Loss_D: 0.4067  Loss_G: 3.7378  D(x): 0.8528    D(G(z)): 0.1870 / 0.0370
[1/5][650/1583] Loss_D: 0.8959  Loss_G: 5.2040  D(x): 0.9486    D(G(z)): 0.4936 / 0.0098
[1/5][700/1583] Loss_D: 0.8076  Loss_G: 5.7948  D(x): 0.9596    D(G(z)): 0.4786 / 0.0065
[1/5][750/1583] Loss_D: 0.6345  Loss_G: 1.6924  D(x): 0.6487    D(G(z)): 0.0841 / 0.2230
[1/5][800/1583] Loss_D: 0.4325  Loss_G: 3.8068  D(x): 0.8621    D(G(z)): 0.2104 / 0.0364
[1/5][850/1583] Loss_D: 0.4938  Loss_G: 2.8332  D(x): 0.8015    D(G(z)): 0.1849 / 0.0832
[1/5][900/1583] Loss_D: 0.5018  Loss_G: 2.9537  D(x): 0.8006    D(G(z)): 0.2060 / 0.0681
[1/5][950/1583] Loss_D: 0.6825  Loss_G: 5.0203  D(x): 0.8992    D(G(z)): 0.3923 / 0.0105
[1/5][1000/1583]        Loss_D: 0.6246  Loss_G: 2.5072  D(x): 0.6270    D(G(z)): 0.0350 / 0.1190
[1/5][1050/1583]        Loss_D: 0.3796  Loss_G: 3.2205  D(x): 0.8104    D(G(z)): 0.1304 / 0.0565
[1/5][1100/1583]        Loss_D: 0.7117  Loss_G: 3.5672  D(x): 0.7659    D(G(z)): 0.2879 / 0.0471
[1/5][1150/1583]        Loss_D: 0.4687  Loss_G: 2.8076  D(x): 0.8072    D(G(z)): 0.1823 / 0.0803
[1/5][1200/1583]        Loss_D: 0.6657  Loss_G: 3.7986  D(x): 0.8693    D(G(z)): 0.3553 / 0.0407
[1/5][1250/1583]        Loss_D: 0.9450  Loss_G: 6.1229  D(x): 0.9538    D(G(z)): 0.5346 / 0.0045
[1/5][1300/1583]        Loss_D: 0.9099  Loss_G: 1.6475  D(x): 0.4693    D(G(z)): 0.0151 / 0.2575
[1/5][1350/1583]        Loss_D: 1.1330  Loss_G: 4.3785  D(x): 0.9068    D(G(z)): 0.5545 / 0.0234
[1/5][1400/1583]        Loss_D: 0.4484  Loss_G: 2.4193  D(x): 0.8307    D(G(z)): 0.1971 / 0.1287
[1/5][1450/1583]        Loss_D: 0.5550  Loss_G: 1.9897  D(x): 0.6497    D(G(z)): 0.0497 / 0.1854
[1/5][1500/1583]        Loss_D: 0.7170  Loss_G: 1.7392  D(x): 0.6460    D(G(z)): 0.1360 / 0.2331
[1/5][1550/1583]        Loss_D: 0.7729  Loss_G: 4.5233  D(x): 0.8350    D(G(z)): 0.4010 / 0.0147
[2/5][0/1583]   Loss_D: 0.5697  Loss_G: 1.9965  D(x): 0.7092    D(G(z)): 0.1606 / 0.1655
[2/5][50/1583]  Loss_D: 0.5735  Loss_G: 3.6139  D(x): 0.8780    D(G(z)): 0.3290 / 0.0392
[2/5][100/1583] Loss_D: 0.5179  Loss_G: 3.5577  D(x): 0.8344    D(G(z)): 0.2572 / 0.0396
[2/5][150/1583] Loss_D: 0.4828  Loss_G: 2.4611  D(x): 0.7614    D(G(z)): 0.1465 / 0.1181
[2/5][200/1583] Loss_D: 0.6025  Loss_G: 3.1642  D(x): 0.8865    D(G(z)): 0.3457 / 0.0627
[2/5][250/1583] Loss_D: 0.5248  Loss_G: 3.2817  D(x): 0.8344    D(G(z)): 0.2561 / 0.0559
[2/5][300/1583] Loss_D: 0.5847  Loss_G: 2.7747  D(x): 0.8016    D(G(z)): 0.2614 / 0.0877
[2/5][350/1583] Loss_D: 0.5929  Loss_G: 3.0085  D(x): 0.8223    D(G(z)): 0.2842 / 0.0703
[2/5][400/1583] Loss_D: 0.8481  Loss_G: 4.2810  D(x): 0.8821    D(G(z)): 0.4557 / 0.0231
[2/5][450/1583] Loss_D: 0.6355  Loss_G: 2.6499  D(x): 0.7537    D(G(z)): 0.2542 / 0.0982
[2/5][500/1583] Loss_D: 0.6343  Loss_G: 2.0048  D(x): 0.6352    D(G(z)): 0.0969 / 0.1709
[2/5][550/1583] Loss_D: 0.5421  Loss_G: 1.4189  D(x): 0.6677    D(G(z)): 0.0761 / 0.2873
[2/5][600/1583] Loss_D: 0.5504  Loss_G: 2.2216  D(x): 0.6783    D(G(z)): 0.1042 / 0.1522
[2/5][650/1583] Loss_D: 0.5841  Loss_G: 2.0702  D(x): 0.7615    D(G(z)): 0.2222 / 0.1617
[2/5][700/1583] Loss_D: 0.7725  Loss_G: 1.4829  D(x): 0.5758    D(G(z)): 0.1184 / 0.2755
[2/5][750/1583] Loss_D: 0.9194  Loss_G: 0.7668  D(x): 0.5202    D(G(z)): 0.1339 / 0.5075
[2/5][800/1583] Loss_D: 1.6557  Loss_G: 5.7321  D(x): 0.9610    D(G(z)): 0.7585 / 0.0058
[2/5][850/1583] Loss_D: 0.4959  Loss_G: 2.5916  D(x): 0.8390    D(G(z)): 0.2488 / 0.0936
[2/5][900/1583] Loss_D: 0.6071  Loss_G: 2.7177  D(x): 0.8098    D(G(z)): 0.2883 / 0.0864
[2/5][950/1583] Loss_D: 0.7837  Loss_G: 1.7942  D(x): 0.6445    D(G(z)): 0.2232 / 0.2139
[2/5][1000/1583]        Loss_D: 0.9329  Loss_G: 1.5548  D(x): 0.4819    D(G(z)): 0.0419 / 0.2593
[2/5][1050/1583]        Loss_D: 2.4020  Loss_G: 0.8285  D(x): 0.1395    D(G(z)): 0.0066 / 0.4939
[2/5][1100/1583]        Loss_D: 0.5012  Loss_G: 3.3053  D(x): 0.9232    D(G(z)): 0.3176 / 0.0495
[2/5][1150/1583]        Loss_D: 0.8440  Loss_G: 2.5003  D(x): 0.7114    D(G(z)): 0.3324 / 0.1098
[2/5][1200/1583]        Loss_D: 1.3791  Loss_G: 6.1866  D(x): 0.9820    D(G(z)): 0.6783 / 0.0036
[2/5][1250/1583]        Loss_D: 0.9269  Loss_G: 4.0669  D(x): 0.9265    D(G(z)): 0.5018 / 0.0268
[2/5][1300/1583]        Loss_D: 1.1773  Loss_G: 4.5318  D(x): 0.9573    D(G(z)): 0.6260 / 0.0167
[2/5][1350/1583]        Loss_D: 0.6199  Loss_G: 1.7171  D(x): 0.6734    D(G(z)): 0.1436 / 0.2343
[2/5][1400/1583]        Loss_D: 0.8173  Loss_G: 3.9755  D(x): 0.8568    D(G(z)): 0.4083 / 0.0270
[2/5][1450/1583]        Loss_D: 0.6914  Loss_G: 3.7235  D(x): 0.9067    D(G(z)): 0.4082 / 0.0322
[2/5][1500/1583]        Loss_D: 1.1643  Loss_G: 1.4965  D(x): 0.4822    D(G(z)): 0.2279 / 0.2689
[2/5][1550/1583]        Loss_D: 0.5028  Loss_G: 3.0822  D(x): 0.8757    D(G(z)): 0.2830 / 0.0598
[3/5][0/1583]   Loss_D: 0.6390  Loss_G: 1.8736  D(x): 0.6246    D(G(z)): 0.0855 / 0.1957
[3/5][50/1583]  Loss_D: 0.6901  Loss_G: 1.3990  D(x): 0.6098    D(G(z)): 0.1155 / 0.2921
[3/5][100/1583] Loss_D: 1.2015  Loss_G: 0.6377  D(x): 0.3686    D(G(z)): 0.0356 / 0.5730
[3/5][150/1583] Loss_D: 0.4790  Loss_G: 2.3582  D(x): 0.7730    D(G(z)): 0.1722 / 0.1234
[3/5][200/1583] Loss_D: 0.6280  Loss_G: 2.7742  D(x): 0.7850    D(G(z)): 0.2823 / 0.0813
[3/5][250/1583] Loss_D: 0.9244  Loss_G: 4.7782  D(x): 0.9574    D(G(z)): 0.5340 / 0.0116
[3/5][300/1583] Loss_D: 0.8196  Loss_G: 1.2503  D(x): 0.5383    D(G(z)): 0.1085 / 0.3391
[3/5][350/1583] Loss_D: 0.6799  Loss_G: 1.9872  D(x): 0.7868    D(G(z)): 0.3136 / 0.1700
[3/5][400/1583] Loss_D: 1.8579  Loss_G: 0.9309  D(x): 0.2019    D(G(z)): 0.0154 / 0.4508
[3/5][450/1583] Loss_D: 0.8013  Loss_G: 4.0926  D(x): 0.8845    D(G(z)): 0.4557 / 0.0224
[3/5][500/1583] Loss_D: 0.7820  Loss_G: 1.6548  D(x): 0.5635    D(G(z)): 0.0975 / 0.2377
[3/5][550/1583] Loss_D: 0.7277  Loss_G: 2.7668  D(x): 0.8176    D(G(z)): 0.3725 / 0.0825
[3/5][600/1583] Loss_D: 1.0623  Loss_G: 3.4370  D(x): 0.8053    D(G(z)): 0.5040 / 0.0457
[3/5][650/1583] Loss_D: 0.6584  Loss_G: 1.8084  D(x): 0.6279    D(G(z)): 0.1153 / 0.2124
[3/5][700/1583] Loss_D: 1.2112  Loss_G: 1.0445  D(x): 0.4010    D(G(z)): 0.1065 / 0.4143
[3/5][750/1583] Loss_D: 0.6222  Loss_G: 3.3972  D(x): 0.9095    D(G(z)): 0.3768 / 0.0446
[3/5][800/1583] Loss_D: 0.4395  Loss_G: 2.5235  D(x): 0.7664    D(G(z)): 0.1290 / 0.1048
[3/5][850/1583] Loss_D: 0.6990  Loss_G: 3.1589  D(x): 0.8385    D(G(z)): 0.3633 / 0.0585
[3/5][900/1583] Loss_D: 0.7169  Loss_G: 3.8126  D(x): 0.9025    D(G(z)): 0.4072 / 0.0341
[3/5][950/1583] Loss_D: 0.6418  Loss_G: 3.9410  D(x): 0.9113    D(G(z)): 0.3863 / 0.0261
[3/5][1000/1583]        Loss_D: 0.6294  Loss_G: 2.3754  D(x): 0.6062    D(G(z)): 0.0381 / 0.1369
[3/5][1050/1583]        Loss_D: 0.8291  Loss_G: 1.0451  D(x): 0.6113    D(G(z)): 0.2093 / 0.3854
[3/5][1100/1583]        Loss_D: 0.4642  Loss_G: 2.7122  D(x): 0.8409    D(G(z)): 0.2228 / 0.0860
[3/5][1150/1583]        Loss_D: 1.1024  Loss_G: 0.8556  D(x): 0.4012    D(G(z)): 0.0413 / 0.4844
[3/5][1200/1583]        Loss_D: 0.6470  Loss_G: 2.7994  D(x): 0.8275    D(G(z)): 0.3221 / 0.0842
[3/5][1250/1583]        Loss_D: 0.4463  Loss_G: 2.9370  D(x): 0.8036    D(G(z)): 0.1796 / 0.0688
[3/5][1300/1583]        Loss_D: 0.9861  Loss_G: 5.1946  D(x): 0.9138    D(G(z)): 0.5470 / 0.0088
[3/5][1350/1583]        Loss_D: 0.6742  Loss_G: 1.1480  D(x): 0.6398    D(G(z)): 0.1343 / 0.3688
[3/5][1400/1583]        Loss_D: 0.6520  Loss_G: 3.9770  D(x): 0.8633    D(G(z)): 0.3548 / 0.0278
[3/5][1450/1583]        Loss_D: 1.3857  Loss_G: 1.0229  D(x): 0.3629    D(G(z)): 0.1089 / 0.4135
[3/5][1500/1583]        Loss_D: 0.8115  Loss_G: 3.6715  D(x): 0.9362    D(G(z)): 0.4737 / 0.0372
[3/5][1550/1583]        Loss_D: 0.6021  Loss_G: 3.1531  D(x): 0.8840    D(G(z)): 0.3440 / 0.0553
[4/5][0/1583]   Loss_D: 0.5426  Loss_G: 1.9401  D(x): 0.6770    D(G(z)): 0.0896 / 0.1901
[4/5][50/1583]  Loss_D: 0.7653  Loss_G: 4.2088  D(x): 0.9169    D(G(z)): 0.4461 / 0.0214
[4/5][100/1583] Loss_D: 0.5282  Loss_G: 2.3480  D(x): 0.7460    D(G(z)): 0.1751 / 0.1199
[4/5][150/1583] Loss_D: 0.4728  Loss_G: 1.9026  D(x): 0.7071    D(G(z)): 0.0861 / 0.1964
[4/5][200/1583] Loss_D: 0.7724  Loss_G: 2.4608  D(x): 0.7301    D(G(z)): 0.3160 / 0.1084
[4/5][250/1583] Loss_D: 0.5781  Loss_G: 3.7348  D(x): 0.9022    D(G(z)): 0.3473 / 0.0331
[4/5][300/1583] Loss_D: 0.7610  Loss_G: 3.8057  D(x): 0.8999    D(G(z)): 0.4442 / 0.0301
[4/5][350/1583] Loss_D: 0.6994  Loss_G: 1.2399  D(x): 0.5895    D(G(z)): 0.0949 / 0.3422
[4/5][400/1583] Loss_D: 0.5062  Loss_G: 2.6103  D(x): 0.8063    D(G(z)): 0.2246 / 0.0966
[4/5][450/1583] Loss_D: 0.5352  Loss_G: 2.1093  D(x): 0.7473    D(G(z)): 0.1801 / 0.1530
[4/5][500/1583] Loss_D: 0.6677  Loss_G: 1.9984  D(x): 0.6526    D(G(z)): 0.1427 / 0.1726
[4/5][550/1583] Loss_D: 0.5840  Loss_G: 2.8799  D(x): 0.8003    D(G(z)): 0.2611 / 0.0783
[4/5][600/1583] Loss_D: 1.9389  Loss_G: 0.3643  D(x): 0.2041    D(G(z)): 0.0249 / 0.7196
[4/5][650/1583] Loss_D: 0.4454  Loss_G: 2.7387  D(x): 0.8515    D(G(z)): 0.2246 / 0.0773
[4/5][700/1583] Loss_D: 1.1443  Loss_G: 1.0976  D(x): 0.3858    D(G(z)): 0.0317 / 0.3879
[4/5][750/1583] Loss_D: 0.6811  Loss_G: 2.5618  D(x): 0.7984    D(G(z)): 0.3098 / 0.1008
[4/5][800/1583] Loss_D: 0.4453  Loss_G: 2.3690  D(x): 0.7406    D(G(z)): 0.1012 / 0.1211
[4/5][850/1583] Loss_D: 0.6584  Loss_G: 1.8715  D(x): 0.7129    D(G(z)): 0.2281 / 0.1844
[4/5][900/1583] Loss_D: 0.5264  Loss_G: 3.5405  D(x): 0.8539    D(G(z)): 0.2771 / 0.0398
[4/5][950/1583] Loss_D: 0.6548  Loss_G: 1.5442  D(x): 0.6265    D(G(z)): 0.1269 / 0.2616
[4/5][1000/1583]        Loss_D: 0.7576  Loss_G: 2.9471  D(x): 0.8335    D(G(z)): 0.3898 / 0.0702
[4/5][1050/1583]        Loss_D: 0.4483  Loss_G: 2.0589  D(x): 0.7652    D(G(z)): 0.1382 / 0.1629
[4/5][1100/1583]        Loss_D: 0.7542  Loss_G: 1.1728  D(x): 0.5472    D(G(z)): 0.0578 / 0.3553
[4/5][1150/1583]        Loss_D: 0.6176  Loss_G: 2.9225  D(x): 0.8210    D(G(z)): 0.3084 / 0.0684
[4/5][1200/1583]        Loss_D: 0.5016  Loss_G: 1.9475  D(x): 0.7459    D(G(z)): 0.1431 / 0.1857
[4/5][1250/1583]        Loss_D: 0.6388  Loss_G: 1.6083  D(x): 0.6436    D(G(z)): 0.1227 / 0.2446
[4/5][1300/1583]        Loss_D: 0.5212  Loss_G: 3.6521  D(x): 0.8599    D(G(z)): 0.2800 / 0.0362
[4/5][1350/1583]        Loss_D: 0.7439  Loss_G: 3.3520  D(x): 0.7985    D(G(z)): 0.3651 / 0.0469
[4/5][1400/1583]        Loss_D: 1.5680  Loss_G: 4.5463  D(x): 0.9406    D(G(z)): 0.7180 / 0.0193
[4/5][1450/1583]        Loss_D: 0.5626  Loss_G: 1.5568  D(x): 0.7108    D(G(z)): 0.1564 / 0.2517
[4/5][1500/1583]        Loss_D: 0.8475  Loss_G: 1.2384  D(x): 0.5332    D(G(z)): 0.0653 / 0.3430
[4/5][1550/1583]        Loss_D: 0.4952  Loss_G: 1.9176  D(x): 0.7584    D(G(z)): 0.1644 / 0.1829

Results

Finally, lets check out how we did. Here, we will look at three different results. First, we will see how D and G’s losses changed during training. Second, we will visualize G’s output on the fixed_noise batch for every epoch. And third, we will look at a batch of real data next to a batch of fake data from G.

Loss versus training iteration

Below is a plot of D & G’s losses versus training iterations.

plt.figure(figsize=(10,5))
plt.title("Generator and Discriminator Loss During Training")
plt.plot(G_losses,label="G")
plt.plot(D_losses,label="D")
plt.xlabel("iterations")
plt.ylabel("Loss")
plt.legend()
plt.show()
Generator and Discriminator Loss During Training

Visualization of G’s progression

Remember how we saved the generator’s output on the fixed_noise batch after every epoch of training. Now, we can visualize the training progression of G with an animation. Press the play button to start the animation.

fig = plt.figure(figsize=(8,8))
plt.axis("off")
ims = [[plt.imshow(np.transpose(i,(1,2,0)), animated=True)] for i in img_list]
ani = animation.ArtistAnimation(fig, ims, interval=1000, repeat_delay=1000, blit=True)

HTML(ani.to_jshtml())
dcgan faces tutorial