Skip to content

Files

Latest commit

TensorFlow GAN Teamcopybara-github
TensorFlow GAN Team
and
Jan 16, 2025
bc369b7 · Jan 16, 2025

History

History

examples

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Apr 9, 2024
Aug 7, 2024
Jan 16, 2025
Jan 16, 2025
Apr 9, 2024
Apr 9, 2024
Apr 9, 2024
Apr 9, 2024
Apr 9, 2024
Apr 9, 2024
Apr 9, 2024
Sep 16, 2019
Apr 9, 2024
Apr 9, 2024
Apr 9, 2024
Apr 9, 2024

TF-GAN Examples

TF-GAN is a lightweight library for training and evaluating Generative Adversarial Networks (GANs). GANs have been in a wide range of tasks including image translation, superresolution, and data augmentation. This directory contains fully-working examples. Each subdirectory contains a different working example. The sub-sections below describe each of the problems, and include some sample outputs. Be sure to follow the instructions for how to run the examples.

Steps to run an example

  1. Add the examples directory to your PYTHONPATH environment variable with

    export PYTHONPATH=${TFGAN_REPO}/tensorflow_gan/examples:${PYTHONPATH}

    Be sure to use the location where you cloned this repository.

  2. Add this repository to your PYTHONPATH environment variable so that it can be used for tensorflow_gan instead of any older libraries you might have installed.

    export PYTHONPATH=${TFGAN_REPO}:${PYTHONPATH}
  3. Install the necessary dependencies, which depend on which example you want to run. At a minimum, you will need:

    1. tensorflow
    2. tensorflow_probability
    3. tensorflow_datasets

    You can usually install these with:

    pip install --upgrade $PACKAGE --user
  4. Follow the instructions in the particular example directory's README.md.

Debugging

  1. If you get an error like ImportError: No module named xxx, you might not have set the PYTHONPATH properly. See step #1 above.
  2. If you get an error for something basic like ImportError: No module named absl, you might not have installed all the imports you need.

Steps to add an example

  1. Email joelshor@google.com to propose the idea.
  2. Add a README.md to your new subdirectory. Be sure to include a "How to run" section.
  3. Add a subdirectory with output ex "images" or "audio".
  4. Add a line and high-level summary to this file.
  5. Submit it and profit.

Table of contents

  1. MNIST
  2. MNIST Estimator
  3. CIFAR10
  4. CIFAR10 on Cloud TPU
  5. CycleGAN
  6. StarGAN
  7. StarGAN Estimator
  8. Progressive GAN
  9. Self-Attention GAN

MNIST

Authors: Joel Shor, Yoel Drori

An unconditional GAN, a conditional GAN, and an InfoGAN, all trained on MNIST digits. We use a classifier trained on MNIST digit classification for evaluation.

MNIST Estimator

Author: Joel Shor

Two examples. Both are unconditional GANs trained on MNIST using the tfgan.estimator.GANEstimator, which reduces code complexity and abstracts away the training details. The first uses the tf.Estimator "blessed" method using train_and_evaluate. The second example uses custom estimator calls.

CIFAR10

Author: Joel Shor

We train a DCGAN generator to produce CIFAR10 images. The unconditional case maps noise to CIFAR10 images. The conditional case maps noise and image class to CIFAR10 images. We use the Inception Score to evaluate the images.

CIFAR10 on Cloud TPU

Authors: Tom Brown, Joel Shor, David Westbrook

This colaboratory notebook introduces you to using TF-GAN's TPUGANEstimator to train GANs on Google's cloud TPU. This infrastructure gives you unprecedented compute power and batch size. In less than five minutes, you can train an unconditional GAN on CIFAR10.

CycleGAN

Author: Shuo Chen and Cassandra Xia

Based on the paper "Unpaired Image-to-Image Translation using Cycle-Consistent Adversarial Networks", this example converts one set of images into another set in an unpaired way.

StarGAN

Author: Wesley Qian

A StarGAN implementation for multi-domain image translation. We run StarGAN on the CelebA dataset.

StarGAN Estimator

Author: Wesley Qian

An Estimator implementation of the example above using tfgan.estimator.StarGANEstimator.

Progressive GAN

Author: Shuo Chen

An implementation of the technique described in Progressive Growing of GANs for Improved Quality, Stability, and Variation. We run the network on the CIFAR10 dataset.

Self-Attention GAN

Author: Yoel Drori, Augustus Odena, Joel Shor

An implementation of Self-Attention Generative Adversarial Networks. The generator produces downsampled ImageNet images. It can be trained on GPU or cloud TPU.