Compare GAN

This repository offers TensorFlow implementations for many components related to Generative Adversarial Networks:

The code is configurable via Gin and runs on GPU/TPU/CPUs. Several research papers make use of this repository, including:

  1. Are GANs Created Equal? A Large-Scale Study [Code] \ Mario Lucic, Karol Kurach, Marcin Michalski, Sylvain Gelly, Olivier Bousquet [NeurIPS 2018]

  2. The GAN Landscape: Losses, Architectures, Regularization, and Normalization [Code] [Colab] \ Karol Kurach, Mario Lucic, Xiaohua Zhai, Marcin Michalski, Sylvain Gelly [ICML 2019]

  3. Assessing Generative Models via Precision and Recall [Code] \ Mehdi S. M. Sajjadi, Olivier Bachem, Mario Lucic, Olivier Bousquet, Sylvain Gelly [NeurIPS 2018]

  4. GILBO: One Metric to Measure Them All [Code] \ Alexander A. Alemi, Ian Fischer [NeurIPS 2018]

  5. A Case for Object Compositionality in Deep Generative Models of Images [Code] \ Sjoerd van Steenkiste, Karol Kurach, Sylvain Gelly [2018]

  6. On Self Modulation for Generative Adversarial Networks [Code] \ Ting Chen, Mario Lucic, Neil Houlsby, Sylvain Gelly [ICLR 2019]

  7. Self-Supervised GANs via Auxiliary Rotation Loss [Code] [Colab] \ Ting Chen, Xiaohua Zhai, Marvin Ritter, Mario Lucic, Neil Houlsby [CVPR 2019]

  8. High-Fidelity Image Generation With Fewer Labels [Code] [Blog Post] [Colab] \ Mario Lucic, Michael Tschannen, Marvin Ritter*, Xiaohua Zhai, Olivier Bachem, Sylvain Gelly [ICML 2019]

Installation

You can easily install the library and all necessary dependencies by running: pip install -e . from the compare_gan/ folder.

Running experiments

Simply run the main.py passing a --model_dir (this is where checkpoints are stored) and a --gin_config (defines which model is trained on which data set and other training options). We provide several example configurations in the example_configs/ folder:

Training and evaluation

To see all available options please run python main.py --help. Main options:

Training on Cloud TPUs

We recommend using the ctpu tool to create a Cloud TPU and corresponding Compute Engine VM. We use v3-128 Cloud TPU v3 Pod for training models on ImageNet in 128x128 resolutions. You can use smaller slices if you reduce the batch size (options.batch_size in the Gin config) or model parameters. Keep in mind that the model quality might change. Before training make sure that the environment variable TPU_NAME is set. Running evaluation on TPUs is currently not supported. Use a VM with a single GPU instead.

Datasets

Compare GAN uses TensorFlow Datasets and it will automatically download and prepare the data. For ImageNet you will need to download the archive yourself. For CelebAHq you need to download and prepare the images on your own. If you are using TPUs make sure to point the training script to your Google Storage Bucket (--tfds_data_dir).