A clean, from-scratch implementation of Deep Convolutional Generative Adversarial Networks (DCGAN) in modern PyTorch, trained on CIFAR-10.
Trains a GAN to generate realistic images from random noise using the DCGAN architecture (Radford et al., 2015). A Generator creates fake images from a latent vector, while a Discriminator learns to distinguish real from fake. They train adversarially until the generator produces convincing outputs.
Random Noise (z=100) → [Generator] → Fake Image (3×64×64)
↓
Real Image (CIFAR-10) → [Discriminator] → Real or Fake?
| Component | Details |
|---|---|
| Generator | 5 transposed conv layers, BatchNorm, ReLU, Tanh out |
| Discriminator | 5 conv layers, BatchNorm, LeakyReLU (0.2), Sigmoid |
| Latent dim | 100 |
| Image size | 64×64×3 |
| Optimizer | Adam (lr=0.0002, β₁=0.5, β₂=0.999) |
| Loss | Binary Cross-Entropy (BCELoss) |
| Epochs | 25 |
pip install torch torchvision- Python 3.7+
- PyTorch ≥ 1.0
- torchvision
cd GANs
python dcgan_commented.pyCIFAR-10 downloads automatically on first run. The results/ directory is created automatically. Generated samples save every 100 steps.
Real samples (CIFAR-10):
Generated samples (epoch 24):
| Tool | Purpose |
|---|---|
| 🐍 Python | Core language |
| 🔥 PyTorch | Deep learning framework |
| 🖼 torchvision | Dataset loading, image transforms, utilities |
| 🧠 DCGAN | Generative adversarial network architecture |
| 📊 CIFAR-10 | Training dataset (60k 32×32 color images) |
- Training for only 25 epochs produces rough outputs. Increase epochs for better quality.
- No checkpointing — training restarts from scratch each run.
- No command-line arguments for hyperparameter tuning.
├── GANs/
│ ├── dcgan_commented.py # Full DCGAN implementation
│ └── results/ # Generated image samples per epoch
├── LICENSE
└── README.md
MIT © Kaustabh Ganguly

