GANs in Tensorflow (Part II)

Sanket Gujar
4 min readMar 31, 2018
MNIST digits generated by the generator.

Welcome to the second post, we will try to code a toy GAN to generate MNIST digits which are very simple. Check out Introduction to GANs before going through this post.

MNIST, MNIST everywhere

So lets get started….

  1. Import all the dependencies
import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt

2. Import the data

from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets(“/tmp/data/” , one_hot= True)

3. Define the parameters for network and training

You can play with the learning rate, hidden layer size and batch size parameters.

epoch           = 100000
batch_size = 128
learning_rate = 2e-4
img_size = 784 #Input Image vector (28x28)
gen_hidden_dim = 256 #Hidden Layer size
disc_hidden_dim = 256 #Hidden Layer size
noise_dim = 100

4. Define the initialization function.

Here we will use Glorot Initialization. For more details you can look up to this good article by Andy

def glorot_init(shape):
std_dev = 1./…

--

--

Sanket Gujar

Computer Science Graduate Student at WPI, Former Perception Intern at Luminar tech, PA. sanketgujar.github.io