Spring 2022 CS 444

Assignment 4: Cat face generation with GANs

Due date: Tuesday, April 19th, 11:59:59PM

Sample images from a GAN trained on the cat face dataset

In this assignment, you will train a generative adversarial network (GAN) on a cat dataset and learn to generate cat face images. You will also implement spectral normalization of discriminator weights to improve the quality of generator images (see Algorithm 1 in Appendix A of the linked paper).

In addition to familiarizing you with generative models and recurrent neural networks, this assignment will help you gain experience with how to implement GANs in PyTorch and how to augment natural images. You will also get familiarised with one of the techniques to imporve the quality of images generated by GANs.

This assignment was adapted from and inspired by material from the Stanford CS231n Assignments, the CMU 16-726 Assignment 3, and the PyTorch Tutorials.

Download the starting code here.

Data setup

Once you have extracted the zip file, go to the assignment folder and execute the download script provided:

cd assignment4_materials/

Alternatively, you can download the cat face dataset from this download link (47.4 MB).

The provided image data are all cropped and resized to the same width and height.


The top-level notebook (MP4.ipynb) will guide you through the steps you need to take to implement and train a GAN. You will train two different models, the original GAN and LSGAN, which has a different loss function. The generator and discriminator network architectures you will implement are roughly based on DCGAN. You will also implement data augmentation via PyTorch's built-in transforms and spectral normalization (spectral_normalization.py) which you will use in your GAN models (for details, see Algorithm 1 of this paper).

We also provide with a notebook to help with debugging called GAN_debugging.ipynb. This notebook provides a small network you can use to train on MNIST. The small network trains very quickly so you can use it to verify that your loss functions and training code are correct.

You will need to use a GPU for training your GAN. We recommend using Colab to debug, but a Google Cloud machine once your debugging is finished. Training the GAN should take roughly an hour at most.

For reference, here are some samples of GAN (left) and LSGAN (right) output at various points during training:

Extra Credit

Implement an alternative GAN formulation like WGAN/WGAN-GP, DRAGAN, or BEGAN.

Useful Pointers

Environment Setup (Local)

If you will be working on the assignment on a local machine then you will need a python environment set up with the appropriate packages. We suggest that you use Conda to manage python package dependencies (https://conda.io/docs/user-guide/getting-started.html).


The assignment is given to you in the MP4.ipynb file. To open the files on a local machine, ensure that ipython is installed (https://ipython.org/install.html). You may then navigate the assignment directory in terminal and start a local ipython server using the jupyter notebook command.

Submission Instructions

This assignment is due on Canvas on the due date specified above. You must upload the following files:

  1. All of your code (python files and ipynb file) in a single ZIP file. The filename should be netid_mp4_code.zip.
  2. Your MP4 ipython notebook with output cells converted to PDF format. The filename should be netid_mp4_output.pdf.
  3. A brief report in PDF format using this template. The filename should be netid_mp4_report.pdf.

Please refer to course policies on collaborations, late submission, etc.