Tooling for GANs in TensorFlow

Related tags

Deep Learning gan
Overview

TensorFlow-GAN (TF-GAN)

TF-GAN is a lightweight library for training and evaluating Generative Adversarial Networks (GANs).

Structure of the TF-GAN Library

TF-GAN is composed of several parts, which are designed to exist independently:

  • Core: the main infrastructure needed to train a GAN. Set up training with any combination of TF-GAN library calls, custom-code, native TF code, and other frameworks
  • Features: common GAN operations and normalization techniques, such as instance normalization and conditioning.
  • Losses: losses and penalties, such as the Wasserstein loss, gradient penalty, mutual information penalty, etc.
  • Evaluation: standard GAN evaluation metrics. Use Inception Score, Frechet Distance, or Kernel Distance with a pretrained Inception network to evaluate your unconditional generative model. You can also use your own pretrained classifier for more specific performance numbers, or use other methods for evaluating conditional generative models.
  • Examples: simple examples on how to use TF-GAN, and more complicated state-of-the-art examples

Who uses TF-GAN?

Numerous projects inside Google. The following are some published papers that use TF-GAN:

The framework Compare GAN uses TF-GAN, especially the evaluation metrics. Their papers use TF-GAN to ensure consistent and comparable evaluation metrics. Some of those papers are:

Training a GAN model

Training in TF-GAN typically consists of the following steps:

  1. Specify the input to your networks.
  2. Set up your generator and discriminator using a GANModel.
  3. Specify your loss using a GANLoss.
  4. Create your train ops using a GANTrainOps.
  5. Run your train ops.

At each stage, you can either use TF-GAN's convenience functions, or you can perform the step manually for fine-grained control.

There are various types of GAN setup. For instance, you can train a generator to sample unconditionally from a learned distribution, or you can condition on extra information such as a class label. TF-GAN is compatible with many setups, and we demonstrate in the well-tested examples directory

Maintainers

Authors

Comments
  • Update the data provider for ImageNet 2012.

    Update the data provider for ImageNet 2012.

    Since ImageNet changed its rule of downloading the dataset, I could not directly access the dataset via tfds.load. I followed URL to transform local ImageNet 2012 dataset to tfrecord files. However I find it seems to be incompatible with current tfds API, especially tfds.load as it in data_provider.py.

    I am not sure if I should rewriter the data provider to fit the tfrecord files processed by URL since I am afraid the re-implementation may change the training behavior and lead to an unfair comparison or inexact reproduction.

    BTW, what is the correct pipeline to reproduce SAGAN from ImageNet 2012 dataset on TPU? I think current one does not work due to the data provider. Should I download the dataset in tar files via imagennet_to_gcs.py in URL and set manual_dir to tfds.load to load it to google cloud storage and continue running data_provider.py, or re-implement the data provider to fit the results from processed tfrecords via URL?

    It confused me since several official implementations from google conflict each other. The reproduction or comparison on ImageNet 2012 is quite expensive thus I start the issue rather than test it by meself.

    Thx for any help!

    opened by Gsunshine 7
  • Update losses module

    Update losses module

    This is in reference to issue #24. I was assigned to make the Tutorial Notebook compatible with Keras instead of the Estimator API.

    I've already made a new input batch generator and Model Architectures using tfv2 functionalities. But I noticed that the losses module also uses certain tfv1 functionalities. For example, the losses_impl.py file uses tf.compat.v1.name_scope instead of tf.name_scope. I'd like to update the losses module to be tfv2 compatible.

    I'm willing to contribute. Please assign this to me.

    opened by SauravMaheshkar 6
  • Update MNIST Example Readme command

    Update MNIST Example Readme command

    When I run the original command, I get this error:

    $ python mnist/train.py --gan_type=conditional --train_log_dir_mnist=/tmp/mnist
    WARNING:tensorflow:From /home/username/Code/gan_examples/gan/tensorflow_gan/python/estimator/tpu_gan_estimator.py:42: The name tf.estimator.tpu.TPUEstimator is deprecated. Please use tf.compat.v1.estimator.tpu.TPUEstimator instead.
    
    WARNING:tensorflow:From /home/username/.asdf/installs/python/anaconda3-2020.07/lib/python3.8/site-packages/tensorflow/python/compat/v2_compat.py:96: disable_resource_variables (from tensorflow.python.ops.variable_scope) is deprecated and will be removed in a future version.
    Instructions for updating:
    non-resource variables are not supported in the long term
    FATAL Flags parsing error: Unknown command line flag 'train_log_dir_mnist'. Did you mean: train_log_dir ?
    Pass --helpshort or --helpfull to see help on flags.
    

    And indeed, changing the command as recommended fixes that issue and gets me into the training loop.

    $ python mnist/train.py --gan_type=conditional --train_log_dir=/tmp/mnist
    WARNING:tensorflow:From /home/username/Code/gan_examples/gan/tensorflow_gan/python/estimator/tpu_gan_estimator.py:42: The name tf.estimator.tpu.TPUEstimator is deprecated. Please use tf.compat.v1.estimator.tpu.TPUEstimator instead.
    
    WARNING:tensorflow:From /home/username/.asdf/installs/python/anaconda3-2020.07/lib/python3.8/site-packages/tensorflow/python/compat/v2_compat.py:96: disable_resource_variables (from tensorflow.python.ops.variable_scope) is deprecated and will be removed in a future version.
    Instructions for updating:
    non-resource variables are not supported in the long term
    I1101 15:52:00.482490 140699447641856 dataset_builder.py:187] Load pre-computed datasetinfo (eg: splits) from bucket.
    I1101 15:52:00.606416 140699447641856 dataset_info.py:410] Loading info from GCS for mnist/3.0.0
    I1101 15:52:01.029893 140699447641856 dataset_builder.py:526] Dataset mnist is hosted on GCS. You can skip download_and_prepare by setting
    data_dir=gs://tfds-data/datasets. If you find
    that read performance is slow, copy the data locally with gsutil:
    gsutil -m cp -R gs://tfds-data/datasets/mnist/3.0.0 /home/username/tensorflow_datasets/mnist
    
    I1101 15:52:01.034518 140699447641856 dataset_builder.py:273] Generating dataset mnist (/home/username/tensorflow_datasets/mnist/3.0.0)
    Downloading and preparing dataset mnist (11.06 MiB) to /home/username/tensorflow_datasets/mnist/3.0.0...
    Dl Completed...: 0 url [00:00, ? url/s]          I1101 15:52:01.036628 140699447641856 download_manager.py:241] Downloading https://storage.googleapis.com/cvdf-datasets/mnist/train-images-idx3-ubyte.gz into /home/username/tensorflow_datasets/downloads/cvdf-datasets_mnist_train-images-idx3-ubyteJAsxAi0QnOBEygBw_XW2X7zp-LBZAIqqYSHN8ru4ZO4.gz.tmp.934a0c84bcab42248ac5454d23b3a2fa...
    Dl Completed...:   0%|
    ...
    

    Checking the directory in question shows that log files are being generated:

    $ ls /tmp/mnist
    checkpoint                                        model.ckpt-1797.data-00000-of-00001  model.ckpt-2185.data-00000-of-00001
    events.out.tfevents.1604274746.computer-name  model.ckpt-1797.index                model.ckpt-2185.index
    graph.pbtxt                                       model.ckpt-1797.meta                 model.ckpt-2185.meta
    model.ckpt-1601.data-00000-of-00001               model.ckpt-1992.data-00000-of-00001  model.ckpt-2380.data-00000-of-00001
    model.ckpt-1601.index                             model.ckpt-1992.index                model.ckpt-2380.index
    model.ckpt-1601.meta                              model.ckpt-1992.meta                 model.ckpt-2380.meta
    
    cla: yes 
    opened by LDonoughe 5
  • Refactor: Moved tensoflow from extra_requires to install_requires

    Refactor: Moved tensoflow from extra_requires to install_requires

    Since TensorFlow is the backbone of TF GAN module so the user might fail or forget to install TF explicitly when in production or a new environment. Hence, it will be nice to move TensorFlow back into install_requires from extra_requires

    cla: yes 
    opened by sanidhyamangal 5
  • Not working

    Not working

    I run this colab in https://colab.research.google.com/github/tensorflow/gan/blob/master/tensorflow_gan/examples/colab_notebooks/tfgan_tutorial.ipynb#scrollTo=83-azWpoYsDg&uniqifier=5&line=10 and found this error

    AttributeError Traceback (most recent call last) in () 8 # Allow matplotlib images to render immediately. 9 get_ipython().magic('matplotlib inline') ---> 10 tf.logging.set_verbosity(tf.logging.ERROR) # Disable noisy outputs.

    AttributeError: module 'tensorflow' has no attribute 'logging'

    opened by rockerritesh 4
  • How to use the Virtual Batch Normalization class?

    How to use the Virtual Batch Normalization class?

    I am currently trying the following using Kera's functional API:

    from tensorflow_gan.python.features import VBN
    
    inputs = Input(shape=(2))
    layer1 = Dense(10, activation="relu")(inputs)
    layer2 = VBN(layer1)(layer1)
    output = Dense(1)(layer2)
    model = Model(inputs=inputs, outputs=output)
    

    But this results in the following error:

    ValueError: The last dimension of the inputs to `Dense` should be defined. Found `None`.
    

    Is this class compatible with the functional API or should I use it in a different way?

    opened by daanklijn 3
  • Colab Tutorial Not TF 2.x Compatible

    Colab Tutorial Not TF 2.x Compatible

    Even though the TF-Gan supports TF 2.x, the Google Colab tutorial is not TF 2.x compatible.

    This should be updated to either lock the version to TF 1.x or update to support TF 2.x.

    opened by dgrahn 3
  • What is the difference between this GAN toolkit and another Google GAN toolkit compare_gan?

    What is the difference between this GAN toolkit and another Google GAN toolkit compare_gan?

    I looked at the documentation, seems very similar toolkits by different Google teams. Even claiming that same papers are using both toolkits.

    https://github.com/google/compare_gan

    Can someone compare gan with compare_gan?

    opened by denfromufa 3
  • Inception score evaluation throwing error

    Inception score evaluation throwing error

    tensorflow 2.0 images are of shape: (28,28,1) inception_score = tfgan.eval.inception_score(images)

    error : Shapes (2, 28, 28, 1) and [None, 299, 299, None] are incompatible

    opened by shubham-malaviya 3
  • How to use input_fn for non tf data?

    How to use input_fn for non tf data?

    I found that the input_function accepts TF dataset and all the examples are being done from tfds dataset. I have hundreds of images scraped and want to have CGGAN for this. Can I have some guidance how to do using TFGAN?

    opened by amitkayal 2
  • Added relativistic losses for ESRGAN Colab.

    Added relativistic losses for ESRGAN Colab.

    Replaced relativistic loss functions defined in the ESRGAN colab notebook with relativistic_generator_loss() and relativistic_discriminator_loss() from TF-GAN losses.

    cla: yes 
    opened by nivedwho 1
  • GAN models for generating HD images

    GAN models for generating HD images

    Thanks a lot for this project! Is there any possibility to add some models which are designed for generating HD images i.e. StyleGAN (StyleGAN2, StyleGAN2-ADA)?

    Thanks in advance!

    opened by wangzizhe 0
  • Performance issue in the definition of _sliced_wasserstein, tensorflow_gan/python/eval/sliced_wasserstein.py

    Performance issue in the definition of _sliced_wasserstein, tensorflow_gan/python/eval/sliced_wasserstein.py

    Hello, I found a performance issue in the definition of _sliced_wasserstein, tensorflow_gan/python/eval/sliced_wasserstein.py, tf.shape(input=a)[1] will calculated repeatedly during the program execution, resulting in reduced efficiency. I think it should be created before the loop in the _sliced_wasserstein.

    Looking forward to your reply. Btw, I am very glad to create a PR to fix it if you are too busy.

    opened by DLPerf 0
  • Issue with tfgan_on_tpus.ipynb in the train step

    Issue with tfgan_on_tpus.ipynb in the train step

    NameError Traceback (most recent call last) in init_global_real_logits() 42 try: ---> 43 real_logits is not None 44 except NameError:

    NameError: name 'real_logits' is not defined

    During handling of the above exception, another exception occurred:

    AssertionError Traceback (most recent call last) 2 frames in get_real_image_logits(num_images, classifier_model) 32 logits = sess.run(real_logits) 33 assert len(logits.shape) == 2 ---> 34 assert logits.shape[0] == num_images 35 return logits 36

    opened by elich11 0
  • Pix2Pix?

    Pix2Pix?

    Hello, hope you're staying safe and healthy! I believe back when gan used to be under tensorflow/models/research, it supported pix2pix directly. Was there a reason why it was removed? My group was reliant on it and I'm migrating our framework from TF1 to TF2, and we didn't catch this change.

    However, I see in the legacy TF1 code that gan.pix2pix used slim.nets.cyclegan.cyclegan_generator_resnet and slim.nets.pix2pix.pix2pix_discriminator. If we want to reimplement the original that's compatible with TF2, would we use tensorflow_gan.examples.cyclegan.generator.cyclegan_generator_resnet and tensorflow_gan.examples.cyclegan.discriminator.pix2pix_discriminator as it is now, define the loss and optimizer as before in gan.pix2pix, and use tensorflow_gan.estimator.GANEstimator? I'm not sure what might no longer be supported.

    But if you happen to have the previous implementation of pix2pix readily available and compatible with tensorflow_gan/TF2, that would be greatly appreciated :) Thanks!

    opened by rachthree 0
  • Update to use keras?

    Update to use keras?

    Hi, this library doesn't seem to have a keras.Model. Keras is the main way many of us interact with TF, so it would be great to see here.

    The TF docs have an example GAN class that works decently well:

    https://www.tensorflow.org/guide/keras/customizing_what_happens_in_fit#wrapping_up_an_end-to-end_gan_example

    But there's no official TF implementation committed anywhere. Would it be possible to add an official TF-GAN keras Model like the one in that example?

    Being able to use Keras makes it much easier for people to learn and experiment with ML, so it would be awesome to see one here.

    Thanks!

    opened by steventrouble 2
Owner
null
bespoke tooling for offensive security's Windows Usermode Exploit Dev course (OSED)

osed-scripts bespoke tooling for offensive security's Windows Usermode Exploit Dev course (OSED) Table of Contents Standalone Scripts egghunter.py fin

epi 268 Jan 5, 2023
Tooling for the Common Objects In 3D dataset.

CO3D: Common Objects In 3D This repository contains a set of tools for working with the Common Objects in 3D (CO3D) dataset. Download the dataset The

Facebook Research 724 Jan 6, 2023
Tooling for converting STAC metadata to ODC data model

Tooling for converting STAC metadata to ODC data model.

Open Data Cube 65 Dec 20, 2022
EigenGAN Tensorflow, EigenGAN: Layer-Wise Eigen-Learning for GANs

Gender Bangs Body Side Pose (Yaw) Lighting Smile Face Shape Lipstick Color Painting Style Pose (Yaw) Pose (Pitch) Zoom & Rotate Flush & Eye Color Mout

Zhenliang He 321 Dec 1, 2022
StudioGAN is a Pytorch library providing implementations of representative Generative Adversarial Networks (GANs) for conditional/unconditional image generation.

StudioGAN is a Pytorch library providing implementations of representative Generative Adversarial Networks (GANs) for conditional/unconditional image generation.

null 3k Jan 8, 2023
[CVPR 2021] Anycost GANs for Interactive Image Synthesis and Editing

Anycost GAN video | paper | website Anycost GANs for Interactive Image Synthesis and Editing Ji Lin, Richard Zhang, Frieder Ganz, Song Han, Jun-Yan Zh

MIT HAN Lab 726 Dec 28, 2022
Code for the paper "Training GANs with Stronger Augmentations via Contrastive Discriminator" (ICLR 2021)

Training GANs with Stronger Augmentations via Contrastive Discriminator (ICLR 2021) This repository contains the code for reproducing the paper: Train

Jongheon Jeong 174 Dec 29, 2022
This is the codebase for Diffusion Models Beat GANS on Image Synthesis.

This is the codebase for Diffusion Models Beat GANS on Image Synthesis.

OpenAI 3k Dec 26, 2022
Implementation of Gans

GAN Generative Adverserial Networks are an approach to generative data modelling using Deep learning methods. I have currently implemented : DCGAN on

Sibam Parida 5 Sep 7, 2021
This is the PyTorch implementation of GANs N’ Roses: Stable, Controllable, Diverse Image to Image Translation

Official PyTorch repo for GAN's N' Roses. Diverse im2im and vid2vid selfie to anime translation.

null 1.1k Jan 1, 2023
[CVPR 2020] Interpreting the Latent Space of GANs for Semantic Face Editing

InterFaceGAN - Interpreting the Latent Space of GANs for Semantic Face Editing Figure: High-quality facial attributes editing results with InterFaceGA

GenForce: May Generative Force Be with You 1.3k Dec 29, 2022
[CVPR 2021] Pytorch implementation of Hijack-GAN: Unintended-Use of Pretrained, Black-Box GANs

Hijack-GAN: Unintended-Use of Pretrained, Black-Box GANs In this work, we propose a framework HijackGAN, which enables non-linear latent space travers

Hui-Po Wang 46 Sep 5, 2022
A PyTorch implementation of ViTGAN based on paper ViTGAN: Training GANs with Vision Transformers.

ViTGAN: Training GANs with Vision Transformers A PyTorch implementation of ViTGAN based on paper ViTGAN: Training GANs with Vision Transformers. Refer

Hong-Jia Chen 127 Dec 23, 2022
PyTorch implementation of Progressive Growing of GANs for Improved Quality, Stability, and Variation.

PyTorch implementation of Progressive Growing of GANs for Improved Quality, Stability, and Variation. Warning: the master branch might collapse. To ob

null 559 Dec 14, 2022
PyTorch implementation of VAGAN: Visual Feature Attribution Using Wasserstein GANs

PyTorch implementation of VAGAN: Visual Feature Attribution Using Wasserstein GANs This code aims to reproduce results obtained in the paper "Visual F

Orobix 93 Aug 17, 2022
Synthesizing and manipulating 2048x1024 images with conditional GANs

pix2pixHD Project | Youtube | Paper Pytorch implementation of our method for high-resolution (e.g. 2048x1024) photorealistic image-to-image translatio

NVIDIA Corporation 6k Dec 27, 2022
PyTorch inference for "Progressive Growing of GANs" with CelebA snapshot

Progressive Growing of GANs inference in PyTorch with CelebA training snapshot Description This is an inference sample written in PyTorch of the origi

null 320 Nov 21, 2022
GAN encoders in PyTorch that could match PGGAN, StyleGAN v1/v2, and BigGAN. Code also integrates the implementation of these GANs.

MTV-TSA: Adaptable GAN Encoders for Image Reconstruction via Multi-type Latent Vectors with Two-scale Attentions. This is the official code release fo

owl 37 Dec 24, 2022