(转) How to Train a GAN? Tips and tricks to make GANs work

How to Train a GAN? Tips and tricks to make GANs work

转自:https://github.com/soumith/ganhacks

While research in Generative Adversarial Networks (GANs) continues to improve the fundamental stability of these models, we use a bunch of tricks to train them and make them stable day to day.

Here are a summary of some of the tricks.

Here‘s a link to the authors of this document

If you find a trick that is particularly useful in practice, please open a Pull Request to add it to the document. If we find it to be reasonable and verified, we will merge it in.

1. Normalize the inputs

  • normalize the images between -1 and 1
  • Tanh as the last layer of the generator output

2: A modified loss function

In GAN papers, the loss function to optimize G is min (log 1-D), but in practice folks practically use max log D

  • because the first formulation has vanishing gradients early on
  • Goodfellow et. al (2014)

In practice, works well:

  • Flip labels when training generator: real = fake, fake = real

3: Use a spherical Z

  • Dont sample from a Uniform distribution

  • Sample from a gaussian distribution

  • When doing interpolations, do the interpolation via a great circle, rather than a straight line from point A to point B
  • Tom White‘s Sampling Generative Networks has more details

4: BatchNorm

  • Construct different mini-batches for real and fake, i.e. each mini-batch needs to contain only all real images or all generated images.
  • when batchnorm is not an option use instance normalization (for each sample, subtract mean and divide by standard deviation).

5: Avoid Sparse Gradients: ReLU, MaxPool

  • the stability of the GAN game suffers if you have sparse gradients
  • LeakyReLU = good (in both G and D)
  • For Downsampling, use: Average Pooling, Conv2d + stride
  • For Upsampling, use: PixelShuffle, ConvTranspose2d + stride

6: Use Soft and Noisy Labels

  • Label Smoothing, i.e. if you have two target labels: Real=1 and Fake=0, then for each incoming sample, if it is real, then replace the label with a random number between 0.7 and 1.2, and if it is a fake sample, replace it with 0.0 and 0.3 (for example).

    • Salimans et. al. 2016
  • make the labels the noisy for the discriminator: occasionally flip the labels when training the discriminator

7: DCGAN / Hybrid Models

  • Use DCGAN when you can. It works!
  • if you cant use DCGANs and no model is stable, use a hybrid model : KL + GAN or VAE + GAN

8: Use stability tricks from RL

  • Experience Replay

    • Keep a replay buffer of past generations and occassionally show them
    • Keep checkpoints from the past of G and D and occassionaly swap them out for a few iterations
  • All stability tricks that work for deep deterministic policy gradients
  • See Pfau & Vinyals (2016)

9: Use the ADAM Optimizer

  • optim.Adam rules!

    • See Radford et. al. 2015
  • Use SGD for discriminator and ADAM for generator

10: Track failures early

  • D loss goes to 0: failure mode
  • check norms of gradients: if they are over 100 things are screwing up
  • when things are working, D loss has low variance and goes down over time vs having huge variance and spiking
  • if loss of generator steadily decreases, then it‘s fooling D with garbage (says martin)

11: Dont balance loss via statistics (unless you have a good reason to)

  • Dont try to find a (number of G / number of D) schedule to uncollapse training
  • It‘s hard and we‘ve all tried it.
  • If you do try it, have a principled approach to it, rather than intuition

For example

while lossD > A:
  train D
while lossG > B:
  train G

12: If you have labels, use them

  • if you have labels available, training the discriminator to also classify the samples: auxillary GANs

13: Add noise to inputs, decay over time

14: [notsure] Train discriminator more (sometimes)

  • especially when you have noise
  • hard to find a schedule of number of D iterations vs G iterations

15: [notsure] Batch Discrimination

  • Mixed results

16: Discrete variables in Conditional GANs

  • Use an Embedding layer
  • Add as additional channels to images
  • Keep embedding dimensionality low and upsample to match image channel size

Authors

  • Soumith Chintala
  • Emily Denton
  • Martin Arjovsky
  • Michael Mathieu
时间: 2024-10-06 12:24:55

(转) How to Train a GAN? Tips and tricks to make GANs work的相关文章

Matlab tips and tricks

matlab tips and tricks and ... page overview: I created this page as a vectorization helper but it grew to become my annotated Matlab reading cache. In order to motivate the DSP people out there, I am showing below how one can apply a window and scal

[转]30 ESSENTIAL PYTHON TIPS AND TRICKS FOR PROGRAMMERS

If you ask any Python programmer to tell about the strengths of Python, he will quote brevity and high readability as the most influencing ones. In this Python tutorial, we’ll cover many essential Python tips and tricks that will authenticate the abo

Tips and Tricks for Debugging in chrome

Tips and Tricks for Debugging in chrome Pretty print On sources panel ,clicking on the {} on the bottom left hand side. Console.table Display data as a table ,improve readability. Add watch expressions Watching variable changes over time. XHR/fetch b

php APC Configuration and Usage Tips and Tricks

原文: https://www.if-not-true-then-false.com/2012/php-apc-configuration-and-usage-tips-and-tricks/ PHP APC (Alternative PHP Cache / Opcode Cache) is framework that optimizes PHP intermediate code and caches data and compiled code from the PHP bytecode

Android Studio 100 tips and tricks

本文是想总结一些Android Studio的使用技巧,对于大多数习惯了使用eclipse的人来说,可能会须要一段时间,可是假设看过以下的一些介绍,你就能体会到Android Studio的强大之处了,只是本文列举的也仅仅是冰山一角,深入了解后会有很多其它值得你发现的! ps:因为时间关系,翻译可能有不全.有错,希望大家能一起修正,请在留言中指出,我会修正-thx 快捷提示:ctrl+space 按住ctrl+shift+上下键 能够将代码行上下移动 启动调试快捷键 alt+shift+F10

Some Tips and Tricks about Qt

刚刚接触qt和qt quick,遇到一些小点子.小陷阱与大家一起分享和学习.csdn中有qt大神安晓辉,我也不敢班门弄斧,只是跟大家一起进步.一起分享. 什么是Qt quick Qt Quick是一个用于帮助开发者设计直观,现代,流畅的用户界面的技术集,近年来被广泛应用于手机,媒体播放器,机顶盒和其他手提设备.Qt Quick中包含了大量的用户界面元素,及描述这些用户界面的陈述性(declarative)语言,和一个语言运行时.在典型的Qt应用程序中有一系列C++ API与这些高层次特性整合.Q

W-GAN系 (Wasserstein GAN、 Improved WGAN)

习总结于国立台湾大学 :李宏毅老师 Wasserstein GAN  .  Improved Training of Wasserstein GANs 本文outline 一句话介绍WGAN: Using Earth Mover's Distance to evaluate two distribution    Earth Mover's Distance(EMD) = Wasserstein Distance 一. WGAN 1.  Earth Mover's Distance(EMD) E

Javascript Tips & Tricks

前端开发规范系列文章之Javascript Tips and Tricks,本意是写成常用代码收集.常用技巧整理的文章,感觉"常用代码大全"太土."实用代码整理"有失偏颇,"提示与技巧"不够稳重,所以使用常用的英语说法,相信广大程序员都懂得. 妙味 Javascript美妙之处,需要我们静静体会,慢慢吸收,然后让代码在您指下曼舞.整理的这些代码我们称之为妙味,请大家细品. 博主会不断更新本文,方便大家阅读起见,我们采用倒序更新的方式,把最新更新的

10 Interesting Linux Command Line Tricks and Tips Worth Knowing

I passionately enjoy working with commands as they offer more control over a Linux system than GUIs(Graphical User Interfaces) applications, therefore am always on the look out to discover or figure out interesting ways and ideas to make Linux so eas