The Discriminator
Learn to define the generator class for the CelebA dataset and check the output of the untrained generator.
We'll cover the following
The discriminator will take an image and try to classify it as real or generated. This is what the MNIST discriminator does so let’s copy that code as a starting point.
The only difference between the MNIST images and the CelebA images are their size and colour depth. The size difference just means we need to change the number of input nodes to the discriminator neural network. The MNIST images were 28 by 28 pixels in size so we had 28 * 28 = 784 input nodes. The CelebA images are 218 by 178 pixels in size. That should mean 218 * 178 input nodes.
📝 Remember that each colour pixel actually has 3 values, one each for the red, green and blue levels. That means each image has a total of 218 * 178 * 3 values. We need to feed all of these to the discriminator because we don’t want to leave any valuable information out. That means the discriminator needs 218 * 178 * 3 = 116,412 input nodes.
A good question to ask is how we should arrange these 116,412 values when we feed them to the discriminator. With the MNIST classifier and discriminator, we just fed the values to the network in the order they appeared in the dataset. Those values followed each pixel along a row in the image, and wrapped round to the next row when the end of a row was reached. As long as we are consistent, the ordering doesn’t actually matter because the neural network layers are fully connected; every node in one layer is connected to every node in the next. This means there is no benefit to a pixel value being at any particular position in the input tensor.
We can do the same for colour images. We can unroll, or reshape, the 218 by 178 by 3 image tensor to a 1-dimensional tensor of length 116,412, and feed that to a fully connected neural network. It doesn’t really matter how we unroll or reshape, as long as we’re consistent and do it the same way every time we feed the discriminator.
The Discriminator
class
Have a look at the following.
Get hands-on with 1400+ tech skills courses.