This repository contains a basic implementation of a Generative Adversarial Network (GAN) using PyTorch, designed to generate handwritten digits similar to the MNIST dataset.
- Generator (G): Takes random noise as input and tries to produce realistic-looking MNIST digit images.
- Discriminator (D): Attempts to distinguish between real MNIST images and the fake images generated by the Generator.
- Both models are trained together in a zero-sum game — G tries to fool D, while D tries not to be fooled.
-
GAN.ipynb— Colab notebook with the full PyTorch code for:- Loading the MNIST dataset.
- Defining the Generator and Discriminator networks.
- Training loop with logging to TensorBoard.
- Python 3
- PyTorch
- Torchvision
- TensorBoard
You can install dependencies using:
pip install torch torchvision tensorboard-
Run the notebook cells:
- The notebook will download MNIST automatically.
- The GAN will train for 50 epochs (by default).
-
Monitor progress:
- Generated fake images and real samples are logged to TensorBoard.
- Run
tensorboard --logdir=logsto see them.
- Latent Vector (z-dim): 64
- Image Dimension: 28×28 = 784
- Optimizer: Adam (
lr = 3e-4) - Loss: Binary Cross Entropy (BCE)
- During training, you can visually compare real vs. generated images.
- Over time, fake images should look more realistic.