A simple Generative Adversarial Network that uses the Fashion MNST dataset and outputs clothing items.
This project aims to set the foundation of Generative Adversial Networks.Once you are able to completely comprehend this model you can further build upon it and explore more complex models such as Conditional GANs,Deep Convoultion GANs,Cycle GANs,Style GANs and so on.
A Genative Adversarial Network is a type of deep learning model that's really good at generating new data that's similar to the data it was trained on.Think of it like an artist learning to paint by studying the works of the masters, and then creating their own original paintings in a similar style.GANs consits of two seperate neural networks which work hand in hand.
The Generator's job is to create new data that looks like the real data.This data could be anything from images to videos to text and music.The Discriminator judges the data and tells the difference between the real data and the fake data created by the generator.
The generator and discriminator are constantly competing with each other.The generator tries to create better and better fake data to fool the discriminator,while the discriminator tries to get better at spotting the fakes. Through this competition,both the networks improve and the generator eventually becomes good at creating fake realstic fake data.
- Tensorflow: Trains the neural Network.
- MatplotLib: Plots all graphs.
- Numpy: Performs complex calculations.
model.add(Dense(7*7*128, input_dim=128)) : The model starts with a dense (fully connected) layer. It takes a 128-dimensional vector of random noise as input.
The output of this dense layer has 7 * 7 * 128 neurons. This effectively maps the random noise to a high-dimensional representation.
model.add(LeakyReLU(0.2)) : A Leaky ReLU activation function is applied. Leaky ReLU is used to prevent the "dying ReLU" problem, where neurons can become inactive.
model.add(Reshape((7,7,128))): The output is then reshaped into a 7x7x128 tensor. This can be thought of as the initial, low-resolution "image" representation that the generator will upsample.
model.add(UpSampling2D()): The UpSampling2D layers double the spatial dimensions (height and width) of the feature maps.
model.add(Conv2D(128, 5, padding='same')): After each upsampling, a 2D convolutional layer is applied. This layer learns to refine the upsampled features. The kernel size is 5x5, and padding='same' ensures that the output has the same dimensions as the input.
model.add(LeakyReLU(0.2)): Another Leaky ReLU activation is applied after each convolutional layer.
This sequence of upsampling and convolution is repeated twice, effectively increasing the image's resolution.
model.add(Conv2D(128, 4, padding='same')): Two more convolutional layers are used for further refinement. These layers have a 4x4 kernel size.
model.add(LeakyReLU(0.2)): Leaky ReLU activations are used again.These convolutional layers help to further define the features of the generated image.
model.add(Conv2D(1, 4, padding='same', activation='sigmoid')): The final convolutional layer produces the output image.
Conv2D(1, ...): It has a single output channel, indicating a grayscale image. For color images, this would be 3 channels (RGB).
activation='sigmoid': The sigmoid activation function is used, which outputs values between 0 and 1. This is typical for generating pixel values of an image..
Model Summary :
Ensure the following libraries and dependencies are installed:
- Python 3.7 or higher
- Required Python libraries:
pip install tensorflow tensorflow-gpu matplotlib tensorflow-datasets ipywidgets
This project is licensed under the MIT License. You are free to use, modify, and distribute the code.
Feel free to reach out with suggestions or improvements!
Reference Video

