The generator

Now we create our generator network. The job of the generator is to take a vector of random noise as input and from this, produce an output image. For this example, we again use fully connected layers that will, at the end, produce an output of a 784 long vector that we can reshape to get our 28x28 image:

def generator(z):
with tf.variable_scope("generator"):
fc1 = tf.layers.dense(inputs=z, units=1024, activation=tf.nn.relu)
fc2 = tf.layers.dense(inputs=fc1, units=1024, activation=tf.nn.relu)
img = tf.layers.dense(inputs=fc2, units=784, activation=tf.nn.tanh)
return img

We use the tanh activation on the output to restrict generated images to be in the range -1 to 1.

Now that the models are defined, we can look at the loss functions that the GAN will need in order to train.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.220.111.87