Compare GAN code.

Overview

Compare GAN

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

  • losses (such non-saturating GAN, least-squares GAN, and WGAN),
  • penalties (such as the gradient penalty),
  • normalization techniques (such as spectral normalization, batch normalization, and layer normalization),
  • neural architectures (BigGAN, ResNet, DCGAN), and
  • evaluation metrics (FID score, Inception Score, precision-recall, and KID score).

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:

  • dcgan_celeba64: DCGAN architecture with non-saturating loss on CelebA 64x64px
  • resnet_cifar10: ResNet architecture with non-saturating loss and spectral normalization on CIFAR-10
  • resnet_lsun-bedroom128: ResNet architecture with WGAN loss and gradient penalty on LSUN-bedrooms 128x128px
  • sndcgan_celebahq128: SN-DCGAN architecture with non-saturating loss and spectral normalization on CelebA-HQ 128x128px
  • biggan_imagenet128: BigGAN architecture with hinge loss and spectral normalization on ImageNet 128x128px

Training and evaluation

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

  • To train the model use --schedule=train (default). Training is resumed from the last saved checkpoint.
  • To evaluate all checkpoints use --schedule=continuous_eval --eval_every_steps=0. To evaluate only checkpoints where the step size is divisible by 5000, use --schedule=continuous_eval --eval_every_steps=5000. By default, 3 averaging runs are used to estimate the Inception Score and the FID score. Keep in mind that when running locally on a single GPU it may not be possible to run training and evaluation simultaneously due to memory constraints.
  • To train and evaluate the model use --schedule=eval_after_train --eval_every_steps=0.

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).

Comments
  • How could you get FID on Fashion-mnist??

    How could you get FID on Fashion-mnist??

    The image of Fashion is gray image which is 28x28x1, but the inception-v3 requires the channels of input image is 3. Thus you transform the size of images from Fashion? If so, how to do it in your code? Thanks, please.

    opened by HuMingqi 5
  • Modernize Python 2 code to prepare for Python 3

    Modernize Python 2 code to prepare for Python 3

    Fixes #4

    • print() is a function in Python 3.
    • unicode() was removed in Python 3 because all str are Unicode.
    • xrange() was removed in Python 3 in favor of range().
    opened by cclauss 5
  • Distributed training

    Distributed training

    Thanks for open sourcing the code for this awesome paper!

    I’m wondering if you used distributed training of the different GAN models during experimentation. If so, could you share an example of how to launch a distributed training job using compare_gan code?

    opened by jppgks 5
  • Is the widening factor of S2GAN's feature extractor really 16?

    Is the widening factor of S2GAN's feature extractor really 16?

    Hi, I've read your paper "High-Fidelity Image GenerationWith Fewer Labels". It's a very fascinating work but I have one question about the pretrained feature extractor F. image

    In the paper you say you use ResNet50 V2 with widening factor 16, which is abnormally large, including 4 times more parameters than the BigGAN discriminator. My computer even cannot successfully construct it in CPU.

    My resnet v2 code is from pytorch official repo https://github.com/pytorch/vision/blob/master/torchvision/models/resnet.py. I wonder whether I am misunderstanding your paper.

    opened by RuiLiFeng 4
  • WGAN gradient penalty coupled with spectral normalization,generator and discriminator loss are both  nan

    WGAN gradient penalty coupled with spectral normalization,generator and discriminator loss are both nan

    gradient penalty coupled with spectral normalization ,two (generator and discriminator) loss are nan. cancel gradient penalty and just use spectral normalization in Ex∼qdata[D(x)]−Ez∼p(z)[D(G(z))],two (generator and discriminator) loss are normal. why?cause i am a noob in deeplearning. thx!

    opened by IPNUISTlegal 4
  • unnecessary batchnorm updates

    unnecessary batchnorm updates

    First of all thank you for this thorough study! There is a slight bug carried out from the dcgan repo to here:

    https://github.com/google/compare_gan/blob/615bdc6fc54e5c074adeee543b779dd504dc7e9f/compare_gan/src/gans/GAN.py#L36

    In here we are passing is_training as a boolean which is true throughout training. This results in batchnorms getting updated when they shouldn't be:

    https://github.com/google/compare_gan/blob/615bdc6fc54e5c074adeee543b779dd504dc7e9f/compare_gan/src/gans/abstract_gan.py#L252

    when we are updating the discriminator weights, we want the batch norms of the generator to not get updated, the same when we are doing discriminator updates.

    A separate is_training flag for the discriminator and generator which is fed-in seems to be the way to do it.

    opened by po0ya 4
  • tensor2tensor not found! even installed t2t

    tensor2tensor not found! even installed t2t

    Hi,

    Ubuntu 1604 MiniConda3 Python3.6.5 TensorFlow1.8.0

    I've cloned this repo and used python -m pip install -e . --user in the director but when I prepare the dataset .tensor2tensor not found! promtps. Dose anyone have any ideas?

    compare_gan$ compare_gan_prepare_datasets.sh 
    tensor2tensor not found!
    compare_gan$ bash compare_gan/bin/compare_gan_prepare_datasets.sh 
    tensor2tensor not found!
    

    so I uninstall compare-gan and install tensor2tensor

    compare_gan$ pip uninstall compare-gan
    Uninstalling compare-gan-1.0:
      Would remove:
        /home/mp/miniconda3/lib/python3.6/site-packages/compare-gan.egg-link
    Proceed (y/n)? y
      Successfully uninstalled compare-gan-1.0
    
    compare_gan$ pip install tensor2tensor
    Requirement already satisfied: pyasn1<0.5.0,>=0.4.1 in /home/mp/miniconda3/lib/python3.6/site-packages (from pyasn1-modules>=0.2.1->google-auth>=1.4.1->google-api-python-client->tensor2tensor) (0.4.3)
    Installing collected packages: tensor2tensor
    Successfully installed tensor2tensor-1.6.3
    
    

    And again using pip install -e . or python -m pip install -e . --user and execute compare_gan_prepare_datasets.sh

    $ compare_gan_prepare_datasets.sh 
    tensor2tensor not found!
    

    Successful for testing t2t

    t2t-trainer \
      --generate_data \
      --data_dir=~/t2t_data \
      --output_dir=~/t2t_train/mnist \
      --problem=image_mnist \
      --model=shake_shake \
      --hparams_set=shake_shake_quick \
      --train_steps=1000 \
      --eval_steps=100
    
    INFO:tensorflow:Finished evaluation at 2018-06-15-05:36:40
    INFO:tensorflow:Saving dict for global step 1000: global_step = 1000, loss = 0.047610797, metrics-image_mnist/targets/accuracy = 0.9956, metrics-image_mnist/targets/accuracy_per_sequence = 0.9956, metrics-image_mnist/targets/accuracy_top5 = 1.0, metrics-image_mnist/targets/neg_log_perplexity = -0.015870268
    INFO:tensorflow:Stop training model as max steps reached
    
    
    opened by Paul0M 4
  • Infogan huge (12g+) model

    Infogan huge (12g+) model

    No matter my inputs, InfoGAN produces a huge model (12g+) causing tpu to close its socket. Changing settings (batch size, image size, number of samples, etc) did not seem to help.

    Samples used were 256x256 RGB images with 4 labels

    From google bucket: model.ckpt-0.data-00000-of-00001 | 12.02 GB

    Log:

    I0606 12:01:05.467655 140082657560448 estimator.py:1111] Calling model_fn.
    
    I0606 12:01:05.468298 140082657560448 datasets.py:210] Running with 1 hosts, modifying dataset seed for host 0 to 547.
    
    I0606 12:01:05.468435 140082657560448 datasets.py:311] train_input_fn(): params={'batch_size': 16, 'context': <tensorflow.contrib.tpu.python.tpu.tpu_context.TPUContext object at 0x7f6752a6f5c0>} seed=547
    
    I0606 12:01:05.512352 140082657560448 modular_gan.py:396] _preprocess_fn(): images=Tensor("arg0:0", shape=(256, 256, 3), dtype=float32, device=/job:worker/task:0/device:CPU:0), labels=Tensor("arg1:0", shape=(4,), dtype=int32, device=/job:worker/task:0/device:CPU:0), seed=547
    
    I0606 12:01:05.526810 140082657560448 tpu_random.py:71] Passing random offset: Tensor("Cast:0", shape=(), dtype=int32, device=/job:worker/task:0/device:CPU:0) with data ({'images': <tf.Tensor 'arg1:0' shape=(256, 256, 3) dtype=float32>, 'z': <tf.Tensor 'arg2:0' shape=(14,) dtype=float32>}, <tf.Tensor 'arg3:0' shape=(4,) dtype=int32>).
    
    I0606 12:01:05.617208 140082657560448 modular_gan.py:529] model_fn(): features={'images': <tf.Tensor 'InfeedQueue/dequeue:1' shape=(2, 256, 256, 3) dtype=float32>, 'z': <tf.Tensor 'InfeedQueue/dequeue:2' shape=(2, 14) dtype=float32>, '_RANDOM_OFFSET': <tf.Tensor 'InfeedQueue/dequeue:0' shape=(2,) dtype=int32>}, labels=Tensor("InfeedQueue/dequeue:3", shape=(2, 4), dtype=int32, device=/device:TPU_REPLICATED_CORE:0),mode=train, params={'batch_size': 2, 'use_tpu': True, 'context': <tensorflow.contrib.tpu.python.tpu.tpu_context.TPUContext object at 0x7f67521429e8>}
    
    W0606 12:01:05.617559 140082657560448 modular_gan.py:537] Graph will be unrolled.
    

    ...

    Generator variables:
    +--------------------------+-----------------+-------------+---------+
    | Name                     | Shape           | Size        | Type    |
    +--------------------------+-----------------+-------------+---------+
    | generator/g_fc1/kernel:0 |      (14, 1024) |      14,336 | float32 |
    | generator/g_fc1/bias:0   |         (1024,) |       1,024 | float32 |
    | generator/g_bn1/gamma:0  |         (1024,) |       1,024 | float32 |
    | generator/g_bn1/beta:0   |         (1024,) |       1,024 | float32 |
    | generator/g_fc2/kernel:0 |  (1024, 524288) | 536,870,912 | float32 |
    | generator/g_fc2/bias:0   |       (524288,) |     524,288 | float32 |
    | generator/g_bn2/gamma:0  |       (524288,) |     524,288 | float32 |
    | generator/g_bn2/beta:0   |       (524288,) |     524,288 | float32 |
    | generator/g_dc3/kernel:0 | (4, 4, 64, 128) |     131,072 | float32 |
    | generator/g_dc3/bias:0   |           (64,) |          64 | float32 |
    | generator/g_bn3/gamma:0  |           (64,) |          64 | float32 |
    | generator/g_bn3/beta:0   |           (64,) |          64 | float32 |
    | generator/g_dc4/kernel:0 |   (4, 4, 3, 64) |       3,072 | float32 |
    | generator/g_dc4/bias:0   |            (3,) |           3 | float32 |
    +--------------------------+-----------------+-------------+---------+
    Total: 538,595,523
    I0606 12:01:08.306834 140082657560448 utils.py:174] 
    Discriminator variables:
    +--------------------------------+-----------------+-------------+---------+
    | Name                           | Shape           | Size        | Type    |
    +--------------------------------+-----------------+-------------+---------+
    | discriminator/d_conv1/kernel:0 |   (4, 4, 3, 64) |       3,072 | float32 |
    | discriminator/d_conv1/bias:0   |           (64,) |          64 | float32 |
    | discriminator/d_conv2/kernel:0 | (4, 4, 64, 128) |     131,072 | float32 |
    | discriminator/d_conv2/bias:0   |          (128,) |         128 | float32 |
    | discriminator/d_fc3/kernel:0   |  (524288, 1024) | 536,870,912 | float32 |
    | discriminator/d_fc3/bias:0     |         (1024,) |       1,024 | float32 |
    | discriminator/d_fc4/kernel:0   |       (1024, 1) |       1,024 | float32 |
    | discriminator/d_fc4/bias:0     |            (1,) |           1 | float32 |
    

    ...

    I0606 12:09:19.918299 140082657560448 tpu_estimator.py:504] Init TPU system
    
    I0606 12:09:27.281899 140082657560448 tpu_estimator.py:510] Initialized TPU in 7 seconds
    
    I0606 12:09:27.785771 140081668916992 tpu_estimator.py:463] Starting infeed thread controller.
    
    I0606 12:09:27.786308 140081652131584 tpu_estimator.py:482] Starting outfeed thread controller.
    
    I0606 12:09:27.928345 140082657560448 tpu_estimator.py:536] Enqueue next (1000) batch(es) of data to infeed.
    
    I0606 12:09:27.928739 140082657560448 tpu_estimator.py:540] Dequeue next (1000) batch(es) of data from outfeed.
    
    I0606 12:09:34.653408 140081652131584 error_handling.py:70] Error recorded from outfeed: Socket closed
    
    opened by CrackerHax 3
  • Unable to evaluate with GPU in colab

    Unable to evaluate with GPU in colab

    I am training dcgan with TPU on colab but when I try to evaluate with GPU I get this TypeError: '<=' not supported between instances of 'int' and 'str'

    This happens with both a fake and real dataset.

    Command used: !python compare_gan/main.py --gin_config example_configs/dcgan_celeba64.gin --data_fake_dataset true --model_dir 'gs://***/models' --tfds_data_dir 'gs://***/' --schedule=continuous_eval --eval_every_steps=0

    Here's the tail of the log: 2019-06-03 05:03:32.856155: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1512] Adding visible gpu devices: 0 2019-06-03 05:03:32.856235: I tensorflow/core/common_runtime/gpu/gpu_device.cc:984] Device interconnect StreamExecutor with strength 1 edge matrix: 2019-06-03 05:03:32.856252: I tensorflow/core/common_runtime/gpu/gpu_device.cc:990] 0 2019-06-03 05:03:32.856264: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1003] 0: N 2019-06-03 05:03:32.856460: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1115] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 14115 MB memory) -> physical GPU (device: 0, name: Tesla T4, pci bus id: 0000:00:04.0, compute capability: 7.5) I0603 05:03:49.514711 140045070399360 fid_score.py:54] Frechet Inception Distance: 433.464. I0603 05:03:49.515237 140045070399360 eval_gan_lib.py:209] Computed results for task <compare_gan.metrics.fid_score.FIDScoreTask object at 0x7f5e5e6a1eb8>: {'fid_score_mean': 433.68958, 'fid_score_std': 0.2974496, 'fid_score_list': '434.10986_433.4947_433.46417'} I0603 05:03:49.515923 140045070399360 runner_lib.py:276] Evaluation result for checkpoint gs://***/models/model.ckpt-0: {'inception_score_mean': 1.0062603, 'inception_score_std': 0.00025255934, 'inception_score_list': '1.0059446_1.0065628_1.0062735', 'fid_score_mean': 433.68958, 'fid_score_std': 0.2974496, 'fid_score_list': '434.10986_433.4947_433.46417'} (default value: -1.0) Traceback (most recent call last): File "compare_gan/main.py", line 133, in <module> app.run(main) File "/usr/local/lib/python3.6/dist-packages/absl/app.py", line 300, in run _run_main(main, args) File "/usr/local/lib/python3.6/dist-packages/absl/app.py", line 251, in _run_main sys.exit(main(argv)) File "compare_gan/main.py", line 127, in main eval_every_steps=FLAGS.eval_every_steps) File "/content/gdrive/My Drive/compare_gan/compare_gan/runner_lib.py", line 354, in run_with_schedule num_averaging_runs=num_eval_averaging_runs) File "/content/gdrive/My Drive/compare_gan/compare_gan/runner_lib.py", line 277, in _run_eval task_manager.add_eval_result(checkpoint_path, result_dict, default_value) File "/content/gdrive/My Drive/compare_gan/compare_gan/runner_lib.py", line 209, in add_eval_result config = self._get_config_for_step(step) File "/content/gdrive/My Drive/compare_gan/compare_gan/runner_lib.py", line 202, in _get_config_for_step last_config_step = sorted([s for s in config_steps if s <= step])[-1] File "/content/gdrive/My Drive/compare_gan/compare_gan/runner_lib.py", line 202, in <listcomp> last_config_step = sorted([s for s in config_steps if s <= step])[-1] TypeError: '<=' not supported between instances of 'int' and 'str'

    opened by CrackerHax 3
  • _model_fn() not implemented

    _model_fn() not implemented

    I tried instantiating a simple WGAN_CP (based on your task 3), but got this error:

    NotImplementedError: _model_fn() must be implemented in subclasses of AbstractGAN.
    

    Looking at the code, there's only one file (compare_gan/src/gans/gans_with_penalty.py) which implements this function. I wonder how this worked for you – is this related to TF version or so?

    I uploaded a gist with a testcase: https://gist.github.com/hmeine/d7ef0c38790dc885f3f73e621e14ff31 There's a button opening the notebook on colab, where you can see that the dependency versions are:

    tensor2tensor                      1.11.0               
    tensorflow                         1.13.0rc1            
    
    opened by hmeine 3
  • Need trainable version for pretrained SSGAN in tfhub

    Need trainable version for pretrained SSGAN in tfhub

    @Marvin182 Hi, the tfhub team has just upload your SSGAN module. It's wonderful but seems dose not have a trainable version. I set m = hub.Module(spec_name, name="gen_module", tags={"gen", "bsNone"}, trainable=True), but the module offers no gradients when optimizor is applied. Below is part of my code. ` class Generator(object):

    def init(self, module_spec, trainable=True): self._module_spec = module_spec self._trainable = trainable self._module = hub.Module(self._module_spec, name="gen_module", tags={"gen", "bsNone"}, trainable=self._trainable) self.input_info = self._module.get_input_info_dict()

    def build_graph(self, input_dict): """ Build tensorflow graph for Generator :param input_dict: {'z_': <hub.ParsedTensorInfo shape=(?, 120) dtype=float32 is_sparse=False>, 'labels': None or (?,)} :return:{'generated': <hub.ParsedTensorInfo shape=(?, 128, 128, 3) dtype=float32 is_sparse=False>} """ inv_input = {} inv_input['z'] = G_mapping_ND(input_dict['z_'], 120, 120) # inv_input['labels'] = input_dict.get('labels', None) self.samples = self._module(inputs=inv_input, as_dict=True)['generated'] return self.samples

    @property def trainable_variables(self): return [var for var in tf.trainable_variables() if 'generator' in var.name] `

    I wonder if it is my implementaion not right or the module itself not trainable.

    opened by RuiLiFeng 2
  • Critical error in the implementation of compare_gan vs the official BigGAN model

    Critical error in the implementation of compare_gan vs the official BigGAN model

    Hello. After roughly one year and 200+ training runs, I finally narrowed down why compare_gan fails to achieve any kind of reasonable result for BigGAN-Deep, and why it fails to achieve the same FID for vanilla BigGAN.

    The answer is that it's missing a + 1 in the conditional batch norm function. Specifically, you must add 1 to gamma so that it's centered around 1. Without this, the model is basically multiplied by zero to start with.

    Good luck to whoever finds this, and godspeed. (Twitter thread with proof that BigGAN-Deep works now: https://twitter.com/theshawwn/status/1342684798905688065 feel free to DM me with questions or whatever.)

    opened by shawwn 0
  • Can't run on v3-8 or v3-32 TPU nodes.

    Can't run on v3-8 or v3-32 TPU nodes.

    Hi, I trained TPU-accelerated GANs from https://github.com/tensorflow/gan without any issues, but can't seem to get compare_gan examples to run on GCP TPUs.

    Here is the general error, which appears whether using ctpu, gcloud, or the online GUI to setup compute resources.

    tensorflow.python.framework.errors_impl.InvalidArgumentError: Cannot assign a device for operation input_pipeline_task0/TensorSliceDataset: node input_pipeline_task0/TensorSliceDataset (defined at /usr/local/lib/python3.5/dist-packages/tensorflow_core/python/framework/ops.py:1748) was explicitly assigned to /job:worker/task:0/device:CPU:0 but available devices are [ /job:localhost/replica:0/task:0/device:CPU:0, /job:localhost/replica:0/task:0/device:XLA_CPU:0 ]. Make sure the device specification refers to a valid device.

    Any thoughts here? Is there a specific python/tensorflow version I should use for running compare_gan?

    Thanks!

    opened by mbbrodie 7
  • tf-nightly-gpu version < 2 no longer exists

    tf-nightly-gpu version < 2 no longer exists

    As tf-nightly-gpu versions below 2 no longer exists on pypi I am using tensorboard==1.12.2 tensorflow==1.12.0 tensorflow-datasets==1.0.1 tensorflow-estimator==1.14.0 tensorflow-gan==0.0.0.dev0 tensorflow-gpu==1.12.0 tensorflow-hub==0.2.0 tensorflow-metadata==0.21.1

    I am able to train using the BigGan network, however when it tries to evaluate I get the error

    Traceback (most recent call last): File "compare_gan/main.py", line 134, in app.run(main) File "/home/odak/.conda/envs/tester_venv2/lib/python3.6/site-packages/absl/app.py", line 299, in run _run_main(main, args) File "/home/odak/.conda/envs/tester_venv2/lib/python3.6/site-packages/absl/app.py", line 250, in _run_main sys.exit(main(argv)) File "compare_gan/main.py", line 128, in main eval_every_steps=FLAGS.eval_every_steps) File "/home/odak/compare_gan/compare_gan/runner_lib.py", line 349, in run_with_schedule gan.as_module_spec(), File "/home/odak/compare_gan/compare_gan/gans/modular_gan.py", line 310, in as_module_spec self._module_fn, tags_and_args=tags_and_args) File "/home/odak/.conda/envs/tester_venv2/lib/python3.6/site-packages/tensorflow_hub/native_module.py", line 189, in create_module_spec if err: raise ValueError(err) ValueError: A state-holding node x of a module's graph (e.g., a Variable op) must not be subject to a tf.colocate_with(y) constraint unless y is also a state-holding node. Details: in the graph for tags set(), node 'generator/embed_y/kernel/ExponentialMovingAverage' has op 'VarHandleOp', which counts as state-holding, but Operation.colocation_groups() == [b'loc:@generator/embed_y/kernel/ExponentialMovingAverage/Read/ReadVariableOp']

    opened by odakiese 0
  • Details in the implementation of BigGAN

    Details in the implementation of BigGAN

    Hi, I find that there are some details in the implementation of BigGAN worth paying attention to.

    First, I notice that the default moments used for batchnorm during inference are the accumulated values: https://github.com/google/compare_gan/blob/3af50e3adcf9bde65deb1b65cd2e784b2e857b3a/example_configs/biggan_imagenet128.gin#L30

    https://github.com/google/compare_gan/blob/e0b739fe71c22068878c317e5943c9f11c570638/compare_gan/architectures/arch_ops.py#L299-L304

    Does it mean that the hyperparameter decay for batchnorm is not used at all? https://github.com/google/compare_gan/blob/3af50e3adcf9bde65deb1b65cd2e784b2e857b3a/example_configs/biggan_imagenet128.gin#L28

    Second, I also notice that the shortcuts are added only when in_channels !=out_channels: https://github.com/google/compare_gan/blob/3af50e3adcf9bde65deb1b65cd2e784b2e857b3a/compare_gan/architectures/resnet_biggan.py#L339 which is different from BigGAN-pytorch: https://github.com/ajbrock/BigGAN-PyTorch/blob/98459431a5d618d644d54cd1e9fceb1e5045648d/layers.py#L388 https://github.com/ajbrock/BigGAN-PyTorch/blob/98459431a5d618d644d54cd1e9fceb1e5045648d/layers.py#L427 that uses shortcuts all the time and the shortcuts are learnable when in_channels !=out_channels or when the block is an upsampling or downsampling block.

    Third, I find that BigGAN-pytorch omit the first relu activation in the first DBlock by setting preactivation=False, which is consistent with the implementation of WGAN-GP(I guess since the range you use for the imput of D is [0,1] instead of [-1, 1], the first relu does not harm). Also, in the shortcut connecting of the first DBlock in WGAN-GP and BigGAN-pytorch, pooling comes before convolution, while in this repo, convolution comes before pooling, as in the other DBlocks.

    Do you think these discrepancy would have a significant influence on the performance of BigGAN?

    Thanks

    opened by tsc2017 2
Owner
Google
Google ❤️ Open Source
Google
DR-GAN: Automatic Radial Distortion Rectification Using Conditional GAN in Real-Time

DR-GAN: Automatic Radial Distortion Rectification Using Conditional GAN in Real-Time Introduction This is official implementation for DR-GAN (IEEE TCS

Kang Liao 18 Dec 23, 2022
A PyTorch-based open-source framework that provides methods for improving the weakly annotated data and allows researchers to efficiently develop and compare their own methods.

Knodle (Knowledge-supervised Deep Learning Framework) - a new framework for weak supervision with neural networks. It provides a modularization for se

null 93 Nov 6, 2022
Compare outputs between layers written in Tensorflow and layers written in Pytorch

Compare outputs of Wasserstein GANs between TensorFlow vs Pytorch This is our testing module for the implementation of improved WGAN in Pytorch Prereq

Hung Nguyen 72 Dec 20, 2022
Pytorch Implementation for CVPR2018 Paper: Learning to Compare: Relation Network for Few-Shot Learning

LearningToCompare Pytorch Implementation for Paper: Learning to Compare: Relation Network for Few-Shot Learning Howto download mini-imagenet and make

Jackie Loong 246 Dec 19, 2022
A lightweight library to compare different PyTorch implementations of the same network architecture.

TorchBug is a lightweight library designed to compare two PyTorch implementations of the same network architecture. It allows you to count, and compar

Arjun Krishnakumar 5 Jan 2, 2023
Code for the paper: Sketch Your Own GAN

Sketch Your Own GAN Project | Paper | Youtube Our method takes in one or a few hand-drawn sketches and customizes an off-the-shelf GAN to match the in

null 677 Dec 28, 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
Code accompanying the paper "Wasserstein GAN"

Wasserstein GAN Code accompanying the paper "Wasserstein GAN" A few notes The first time running on the LSUN dataset it can take a long time (up to an

null 3.1k Jan 1, 2023
Official pytorch code for SSC-GAN: Semi-Supervised Single-Stage Controllable GANs for Conditional Fine-Grained Image Generation(ICCV 2021)

SSC-GAN_repo Pytorch implementation for 'Semi-Supervised Single-Stage Controllable GANs for Conditional Fine-Grained Image Generation'.PDF SSC-GAN:Sem

tyty 4 Aug 28, 2022
Code of Adverse Weather Image Translation with Asymmetric and Uncertainty aware GAN

Adverse Weather Image Translation with Asymmetric and Uncertainty-aware GAN (AU-GAN) Official Tensorflow implementation of Adverse Weather Image Trans

Jeong-gi Kwak 36 Dec 26, 2022
A Fast and Stable GAN for Small and High Resolution Imagesets - pytorch

A Fast and Stable GAN for Small and High Resolution Imagesets - pytorch The official pytorch implementation of the paper "Towards Faster and Stabilize

Bingchen Liu 455 Jan 8, 2023
TransGAN: Two Transformers Can Make One Strong GAN

[Preprint] "TransGAN: Two Transformers Can Make One Strong GAN", Yifan Jiang, Shiyu Chang, Zhangyang Wang

VITA 1.5k Jan 7, 2023
Ultra-Data-Efficient GAN Training: Drawing A Lottery Ticket First, Then Training It Toughly

Ultra-Data-Efficient GAN Training: Drawing A Lottery Ticket First, Then Training It Toughly Code for this paper Ultra-Data-Efficient GAN Tra

VITA 77 Oct 5, 2022
Implementation of 'lightweight' GAN, proposed in ICLR 2021, in Pytorch. High resolution image generations that can be trained within a day or two

512x512 flowers after 12 hours of training, 1 gpu 256x256 flowers after 12 hours of training, 1 gpu Pizza 'Lightweight' GAN Implementation of 'lightwe

Phil Wang 1.5k Jan 2, 2023
A collection of resources on GAN Inversion.

This repo is a collection of resources on GAN inversion, as a supplement for our survey

null 857 Dec 29, 2022
AOT-GAN for High-Resolution Image Inpainting (codebase for image inpainting)

AOT-GAN for High-Resolution Image Inpainting Arxiv Paper | AOT-GAN: Aggregated Contextual Transformations for High-Resolution Image Inpainting Yanhong

Multimedia Research 214 Jan 3, 2023
Implementation of TransGanFormer, an all-attention GAN that combines the finding from the recent GanFormer and TransGan paper

TransGanFormer (wip) Implementation of TransGanFormer, an all-attention GAN that combines the finding from the recent GansFormer and TransGan paper. I

Phil Wang 146 Dec 6, 2022
PyTorch 1.5 implementation for paper DECOR-GAN: 3D Shape Detailization by Conditional Refinement.

DECOR-GAN PyTorch 1.5 implementation for paper DECOR-GAN: 3D Shape Detailization by Conditional Refinement, Zhiqin Chen, Vladimir G. Kim, Matthew Fish

Zhiqin Chen 72 Dec 31, 2022
Invert and perturb GAN images for test-time ensembling

GAN Ensembling Project Page | Paper | Bibtex Ensembling with Deep Generative Views. Lucy Chai, Jun-Yan Zhu, Eli Shechtman, Phillip Isola, Richard Zhan

Lucy Chai 93 Dec 8, 2022