We will better understand InfoGANs by implementing them in TensorFlow step by step. We will use the MNIST dataset and learn how the InfoGAN infers the code automatically based on the generator output. We build an Info-DCGAN; that is, we use convolutional layers in the generator and discriminator instead of a vanilla neural network.
First, we will import all the necessary libraries:
import warnings
warnings.filterwarnings('ignore')
import numpy as np
import tensorflow as tf
from tensorflow.examples.tutorials.mnist import input_data
tf.logging.set_verbosity(tf.logging.ERROR)
import matplotlib.pyplot as plt
%matplotlib inline
Load the MNIST dataset:
data = input_data.read_data_sets("data/mnist",one_hot=True)
Define the leaky ReLU activation function:
def lrelu(X, leak=0.2):
f1 = 0.5 * (1 + leak)
f2 = 0.5 * (1 - leak)
return f1 * X + f2 * tf.abs(X)