Training a DCGAN on MNIST by Author
Deep Convolutional Generative Adversarial Networks or DCGANs are the ‘image version’ of the most fundamental implementation of GANs. This architecture essentially leverages Deep Convolutional Neural Networks to generate images belonging to a given distribution from noisy data using the Generator-Discriminator framework.
Generative Adversarial Networks use a generator network to generate new samples of data and a discriminator network to evaluate the generator’s performance. So, fundamentally, GANs’ novelty lies in the evaluator more than that in the generator.
This is what sets GANs apart from other generative models. The incorporation of a Generative model with a Discriminative model is what GANs are all about
— A Comprehensive Guide to Generative Adversarial Networks (GANs)
I have discussed the theory and math behind GANs in another post, consider giving it a read if you are interested in knowing how GANs work!
In this article, we will implement DCGAN using TensorFlow and observe the results for two well-known datasets:
In this section, we load and prepare the data for our model.
We load the data from tensorflow.keras datasets module, which provides a _load_data _function for obtaining a few well-known datasets (including the ones we need). Then, we normalize the loaded images to have values from -1 to 1 as these have pixel values from 0 to 255.
(train_images, train_labels), (_, _) = tf.keras.datasets.mnist.load_data()
# or
(train_images, train_labels), (_, _) = tf.keras.datasets.cifar10.load_data()
# Normalize the images to [-1, 1]
train_images = (train_images - 127.5) / 127.5
train_dataset = tf.data.Dataset.from_tensor_slices(train_images).shuffle(BUFFER_SIZE).batch(BATCH_SIZE)
view raw
dcgan.py hosted with ❤ by GitHub
Preparing Data for Training
The generator model mainly consists of Deconvolution layers or more accurately, Transposed Convolution layers that basically perform the reverse of a Convolution operation.
#machine-learning #dcgan #deep-learning #deep learning