(转) 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-09-02 08:38:25

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

Android 6.0 Marshmallow tips and tricks 棉花糖的技巧和窍门

Since you're reading these lines, chances are you're among the lucky 2 percent of Android users who happen to have Marshmallow running on their smartphone. You've either received an update to Android 6.0, or you're simply a Nexus user.从你看到这个起,你很幸运的了解

Performance Tips and Tricks in .NET Applications(一

Performance Tips and Tricks in .NET ApplicationsA .NET Developer Platform White PaperEmmanuel SchanzerMicrosoft CorporationAugust 2001Summary: This article is for developers who want to tweak their applications for optimal performance in the managed

ASP.NET AJAX Advance Tips & Tricks(11) 三种方法动态创建Tooltip

前言 如何动态创建提示框(Tooltip)是ASP.NET Forum里的常见问题之一,在做技术支持时,我曾在英文 博客上总结过ASP.NET和ASP.NET AJAX环境下如何动态创建提示框的三种常见方法,比较基础,收到了蛮 多老外们的commend,如今英文博客被墙,特转到这里来与大家分享. 原文地址: http://lancezhang.wordpress.com/2008/12/04/create-tooltip-dynamically/ http://lancezhang.wordpr

ASP.NET AJAX Advance Tips & Tricks (10)

解决使用AJAX Extender时的页面导出(Word/Excel)问题 前言: 有客户问到这么个问题:我们可以使用Response容易地将ASP.NET页面导出为Excel或Word.然而,如 果有AJAX Control Toolkit的Extender在页面上的话,则会发生错误(Extender control 'XXX' is not a registered extender control).我搜索了一下,ASP.NET forum里有很多这样的问题未能解决,故写了 这个解决方案,

ASP.NET AJAX Advance Tips & Tricks (9)

DropDownList在Firefox下的奇怪现象和解决方案--谁的BUG? 前言: 今天在ASP.NET Forum里面遇到了一个及其怪异的问题,一个看似非常简单的demo在IE及其它浏览器中 正常运行,然而在Firefox中却导致了奇怪的问题,使页面中的DropDownList死掉,经过研究,终于找到 了一个解决方案,但此问题是谁的Bug仍不得而知. 问题重现: 一个ScriptManager 一个DropDownList 一个UpdatePanel,内有一个Button 在按钮点击事件中

ASP.NET AJAX Advance Tips & Tricks (8) 扩展AJAX Control Toolkit中的控件

需求: TabContainer容器中的TabPanel类本身就包含了Enabled属性,也可以使用JavaScript方法 set_enabled(X)来设置Enabled属性,如果某个TabPanel的这个属性为false的话,这个TabPanel就不会显 示在TabContainer中,这与一般控件的"Enabled"属性不太一样,我认为叫它"Visiable"会更加恰当 .如下图所示: 有时候这并不符合我们的需求,所以,在本例中,我们将为其添加Disable

ASP.NET AJAX Advance Tips & Tricks (7) ASP.NET AJAX与URLRewriting

前言: 最近一些使用URLRewriting的朋友们有时候会遇到ASP.NET AJAX和AJAX Control Toolkit控件不能正 常工作的现象,对于没有相关经验的开发者来说相当棘手.本篇通过案例分析和相对的解决方案来讨论在 使用ASP.NET AJAX 与 URLRewriting 时应当注意到的一些兼容性问题. 问题重现: 一般简单的URLRewriting应用都是对来自客户端对资源的Request进行路径重定向,比较典型的写法如 同下列代码1 和代码2: 代码1: // If t

ASP.NET AJAX Advance Tips & Tricks (6)

AJAX Control Toolkit与Virtual Earth的兼容问题 前言: Virtual Earth作为微软的地图服务,在技术和实用性上与Google Map有的一拼,某些方面还比Google Map做的要好,用的人也越来越多了.但由于其JavaScript的高度封装特性,最近遇到了不少Virtual Earth与ASP.NET AJAX不兼容的情况.案例既多又复杂,本篇通过一个有代表性的例子来讨论两者的兼容 ,希望能帮助遇到此麻烦的开发者解决问题. 问题重现: 下面的代码将一个V

ASP.NET AJAX Advance Tips & Tricks (5) UpdatePanel与jQuery

前言 现在越来越多的朋友喜欢将jQuery和ASP.NET AJAX 一起来用,最近,许多印度人在forum里抱怨说 UpdatePanel和jQuery不兼容,许多jQuery效果在UpdatePanel更新之后就不work.本篇通过分析两者的框 架结构来解决这个兼容性问题. 问题重现: 1.在页面中添加ScriptManager和UpdatePanel 2.在UpdatePanel中添加元素A 3.用jQuery对元素A添加X效果 4.在UpdatePanel中加一个ButtonB用作pos