Click the button below to generate a synthetic face using my pretrained GAN model.
A GAN for Face Generation
This project implements a Generative Adversarial Network (GAN) designed to generate images (256x256 pixels) from random noise vectors. Built using PyTorch, the code includes a Generator and a Discriminator, trained in an adversarial setup to produce synthetic images.
Architecture Overview
The GAN consists of two primary neural network components:
Generator
- Purpose: Transforms a latent vector (random noise) into a 256x256 RGB image
- Architecture: Series of transposed convolutional layers upsampling from 1x1 to 256x256
- Key Components:
- 4x4 feature map expansion (1024 channels)
- 6 upsampling stages with BatchNorm and ReLU
- Tanh activation for [-1, 1] pixel range
Discriminator
- Purpose: Evaluates image authenticity with probability score
- Architecture: Convolutional layers downsampling from 256x256 to 1x1
- Key Components:
- 6 downsampling stages with LeakyReLU (slope 0.2)
- Sigmoid activation for probability output
- BatchNorm on all layers except first
Implemented Solutions
Training Enhancements
- Label smoothing (real labels = 0.9)
- BCELoss for adversarial training
- Adam optimizer (β1=0.5, β2=0.999)
Technical Innovations
- Weight initialization (mean 0, std 0.02)
- Graceful interruption handling
- Base64 image visualization
- GPU/CPU device agnosticism
Key Features
- 256x256 high-resolution output
- Pre-trained model support
- Real-time loss tracking
- Checkpoint system (epoch + interrupt)
- Dynamic normalization ([-1, 1] → [0, 1])
Note: The implementation uses PyTorch's ImageFolder dataset structure and includes comprehensive visualization utilities for monitoring training progress.