Simple GAN with TensorFlow
Note
You can follow along with the code in the Jupyter notebook ch-14a_SimpleGAN
.
For building the GAN with TensorFlow, we build three networks, two discriminator models, and one generator model with the following steps:
- Start by adding the hyper-parameters for defining the network:
# graph hyperparameters g_learning_rate = 0.00001 d_learning_rate = 0.01 n_x = 784 # number of pixels in the MNIST image # number of hidden layers for generator and discriminator g_n_layers = 3 d_n_layers = 1 # neurons in each hidden layer g_n_neurons = [256, 512, 1024] d_n_neurons = [256] # define parameter ditionary d_params = {} g_params = {} activation = tf.nn.leaky_relu w_initializer = tf.glorot_uniform_initializer b_initializer = tf.zeros_initializer
- Next, define the generator network:
z_p = tf.placeholder(dtype=tf.float32, name='z_p', shape=[None, n_z]) layer = z_p # add generator network weights, biases and layers with tf.variable_scope('g'): for i in range(0, g_n_layers...