# Generative Adversarial Networks in Retinal Image Classification
## 3 The Method
Since the generator model is not intended for a classification task, there is no need to split the dataset into training, validation, and testing sets. The generator requires input images in the format (60,000, 28, 28), indicating that there are 60,000 grayscale training images with dimensions of \(28\times 28\). The loaded data already has the shape (60,000, 28, 28) as it is grayscale. To ensure compatibility with the generator's final layer activation using tanh, we normalize the input images to the range of \([-1,1]\). The primary objective of the generator is to generate realistic images and deceive the discriminator into perceiving them as real. The generator takes random noise as input and generates an image that closely resembles the training images. Given that we are generating grayscale images of size \(28\times 28\), the model architecture needs to ensure that the generator's output has a shape of \(28\times 28\times 1\). To accomplish this, the generator performs the following operations:  
1. Convert the 1D random noise (latent vector) to a 3D shape using the Reshape layer. 2. Upsample the noise iteratively using Keras. 3. Match the Conv2 DTranspose layer (also known as fractional-strided convolution in the paper) to the desired output image size. In our case, we aim to generate grayscale images with a shape of 28 \(\times\) 28 \(\times\) 1. The generator comprises several key layers that serve as its building blocks: 1. Dense (fully connected) layer: used primarily for reshaping and flattening the noise vector. 2. Conv2 DTranspose: employed for upsampling the image during the generation process. 3. BatchNormalization: applied to stabilize the training process. It is positioned after the convolutional layer and before the activation function. In the generator, ReLU activation is utilized for all layers, except the output layer, which employs tanh activation. We developed a function for building the generator model architecture, for which a model summary is shown in Table 1.  
For constructing the generator model, we utilized the Keras Sequential API. The initial step involved creating a Dense layer to reshape the input into a 3D format, with the input shape specified in this layer. Following that, we added BatchNormalization and ReLU layers to the generator model. Subsequently, we reshaped the preceding layer from 1D to 3D and performed two upsampling operations using Conv2 DTranspose layers with a stride of 2. This progression allowed us to increase the size from 7 \(\times\) 7 to 14 \(\times\) 14 and ultimately to 28 \(\times\) 28. After each Conv2 DTranspose layer, we incorporated a BatchNormalization layer, followed by a ReLU layer. Lastly, we included a Conv2D layer with a tanh activation function as the output layer. The generator model comprises a total of 2,343,681 parameters, out of which 2,318,209 parameters are trainable, while the remaining 25,472 parameters are non-trainable. Next, we will delve into the implementation of the discriminator model. The discriminator functions as a binary classifier that discerns whether an image is real or fake. Its primary aim is to accurately classify the provided images. However, there are a few notable differences between a discriminator and a conventional classifier:  
In the discriminator, we employ the LeakyReLU activation function. The discriminator encounters two categories of input images: real images sourced from the training dataset, labeled as 1, and fake images generated by the generator, labeled as 0. It is worth noting that the discriminator network is usually designed to be smaller or simpler than the generator. This is because the discriminator has a relatively easier task compared to the generator. In fact, if the discriminator becomes too strong, it can impede the progress of the generator. Table 2 shows the model summary related to the discriminator model. To create the discriminator model, we define a function that takes input consisting of either real images from the training dataset or fake images generated by the generator.