PyTorch implementation for the assignment: Part 1 (GANs from scratch on 2D data) and Part 2 (three applied GANs — medicine, cybersecurity, creative AI), each with its extension task.
python -m venv venv && source venv/bin/activate
pip install -r requirements.txtTested with Python 3.10, torch 2.6 (CPU). No GPU required (everything was trained on CPU); a GPU will simply be faster.
code/ all scripts (see below)
data/ datasets (downloaded automatically / see links in scripts)
figures/ all figures used in the report
outputs/ loss CSVs, FID values, cached features
checkpoints/ saved generator/discriminator weights (resumable training)
report/ report skeleton & writing notes
Run from inside code/.
Part 1 — 2D GANs (sine, mixture of Gaussians, modified architecture)
python part1_gan_2d.pyPart 2.1 — PneumoniaMNIST DCGAN (+ conditional GAN extension)
python part2_1_pneumonia_dcgan.py --explore # data figures
python part2_1_pneumonia_dcgan.py --epochs 40 # train (resumable, run in chunks if needed)
python compute_fid.py --tag p21 --real --n 600 # FID, phase 1
python compute_fid.py --tag p21 --fake --n 600 # FID, phase 2
python compute_fid.py --tag p21 --score # FID result
python part2_1b_pneumonia_cgan.py --epochs 28 # conditional GAN extension
python part2_1b_pneumonia_cgan.py --grid # per-class on-demand gridPart 2.2 — CIC-IDS-2017 tabular GAN (+ all-days extension)
python part2_2_cicids_gan.py --preprocess
python part2_2_cicids_gan.py --epochs 218
python part2_2_cicids_gan.py --evaluate # PCA + t-SNE + metrics
python part2_2b_cicids_alldays.py --preprocess # extension: DoS+DDoS+PortScan
python part2_2b_cicids_alldays.py --epochs 138
python part2_2b_cicids_alldays.py --evaluatePart 2.3 — QuickDraw broccoli DCGAN (+ second-category extension)
python part2_3_broccoli_dcgan.py --explore
python part2_3_broccoli_dcgan.py --epochs 27
python part2_3_broccoli_dcgan.py --final
python compute_fid.py --tag p23 --real --n 600
python compute_fid.py --tag p23 --fake --n 600
python compute_fid.py --tag p23 --score
python part2_3b_other_category.py --category cat --explore
python part2_3b_other_category.py --category cat --epochs 18
python part2_3b_other_category.py --category cat --final- Training scripts checkpoint after every epoch and resume automatically, so
long runs can be done in short chunks (
--epochs Ncontinues from the last checkpoint). gan_utils.pyholds shared helpers: DCGAN weight init, image-grid saving, the InceptionV3-based FID, and checkpoint load/save.- Datasets: PneumoniaMNIST (MedMNIST/Zenodo), CIC-IDS-2017 (Wednesday + Friday
CSVs), QuickDraw
broccoli/cat.npybitmaps. Download URLs are in the scripts / were fetched intodata/.
| Task | Metric |
|---|---|
| 2.1 X-ray DCGAN | FID 66.4 |
| 2.2 traffic GAN | per-feature mean gap 0.084 / std gap 0.370 |
| 2.3 broccoli DCGAN | FID 91.7 |
| 2.3 ext. cat DCGAN | FID 160.7 |