This project implements a Generative Adversarial Network (GAN) to generate synthetic images of handwritten digits from the MNIST dataset. The GAN is trained to produce realistic digit images that closely resemble the real data. These generated images can be useful for data augmentation, image synthesis, and various computer vision tasks.
Usage:
Run the provided code in a Python environment (e.g., Google Colab) with GPU support for faster training. The GAN will be trained for a specified number of epochs (100 epochs by default). After training, the code will generate a set of synthetic digit images and save them as PNG files. You can view the generated images to observe the GAN's performance. Dependencies:
Python 3.x TensorFlow 2.x NumPy Matplotlib
-
Data Loading: It loads the MNIST dataset, which consists of 28x28 grayscale images of handwritten digits (0 through 9). The dataset is preprocessed and normalized to be within the range [-1, 1].
-
Generator and Discriminator Models: It defines two neural network models:
- Generator: This model takes random noise as input and generates fake images that are meant to resemble handwritten digits.
- Discriminator: This model takes both real images from the dataset and fake images generated by the generator. Its task is to distinguish between real and fake images.
-
Loss Functions: It defines loss functions for both the generator and discriminator. The generator tries to generate images that the discriminator cannot distinguish from real images, while the discriminator tries to correctly classify real and fake images.
-
Optimizers: It specifies the optimizers (Adam in this case) for both the generator and discriminator models.
-
Training Loop: It contains a training loop where the generator and discriminator are trained alternately. During each iteration of the loop, the generator generates fake images, and the discriminator is trained to distinguish between real and fake images.
-
Generation of Images: After training for a specified number of epochs, the code generates a set of fake images using the trained generator. These generated images are then saved as PNG files.