dulaku / StyleGAN-for-Humans

A PyTorch implementation of StyleGAN optimized for human reading.
7 stars 2 forks source link

StyleGAN For Humans

A Pytorch implementation of the model presented in "A Style-Based Generator Architecture for Generative Adversarial Networks". No training videos this time - I've run this enough to be pretty sure it's working, but I can't justify pulling my machine off COVID19 folding long enough to get a convincing video to upload.

This is a sequel to ProGAN For Humans. The goal here is for the code to be easily interpretable, with a lot of comments explaining why we're doing things, under the assumption the reader isn't already an expert. A large amount of code here is directly reused; the major updates have been made to:

The recommended reading order is train.py, stylegan_dataloader.py, stylegan_models.py, stylegan_layers.py. You'll want to understand what the style mixer is doing for the style mixing logic in the model itself to make sense. This doesn't feel particularly intuitive or readable, so suggestions welcome.

Compared to the code in the original project, there are 4 major differences:

As before, readability of the code was the highest priority, so some features are lacking and I would not expect a production-ready code base. In particular:

In general, I try to assume you have the paper on hand - comments don't generally explain "why"s that are covered in the paper, but instead try to give enough information that you know what part of the paper is relevant. Likewise, the code assumes a basic level of familiarity with convolutional neural networks. If you don't have that yet, I strongly recommend the following resources:

Requirements:

The following Python modules are required. I recommend installing the Python requirement with venv or something similar.

You will also need a dataset of 1024x1024 images. In principle, you should use the FFHQ dataset. In practice, I've been trying to download this thing for a solid month but Google Drive has a quota that has kept me from succeeding.

You may also find it helpful to set the environment variable CUDA_VISIBLE_DEVICES=1,0 - your OS may be using some VRAM on your 0th GPU, so reversing them for Pytorch can give you just a bit more room on the GPU used for unparallelized scratch space.