Improved Techniques for Training GANs

Tim Salimans, Ian Goodfellow, Wojciech Zaremba, Vicki Cheung, Alec Radford, Xi Chen

Introduction

Generative adversarial networks (GANs) are a class of methods for learning generative models based on game theory. The goal of GANs is to train a generator network G(z;θ(G))G({\bm{z}};{\bm{\theta}}^{(G)}) that produces samples from the data distribution, pdata(x)p_{\rm{data}}({\bm{x}}), by transforming vectors of noise z{\bm{z}} as x=G(z;θ(G)){\bm{x}}=G({\bm{z}};{\bm{\theta}}^{(G)}). The training signal for GG is provided by a discriminator network D(x)D({\bm{x}}) that is trained to distinguish samples from the generator distribution pmodel(x)p_{\rm{model}}({\bm{x}}) from real data. The generator network GG in turn is then trained to fool the discriminator into accepting its outputs as being real.

Recent applications of GANs have shown that they can produce excellent samples . However, training GANs requires finding a Nash equilibrium of a non-convex game with continuous, high-dimensional parameters. GANs are typically trained using gradient descent techniques that are designed to find a low value of a cost function, rather than to find the Nash equilibrium of a game. When used to seek for a Nash equilibrium, these algorithms may fail to converge .

In this work, we introduce several techniques intended to encourage convergence of the GANs game. These techniques are motivated by a heuristic understanding of the non-convergence problem. They lead to improved semi-supervised learning peformance and improved sample generation. We hope that some of them may form the basis for future work, providing formal guarantees of convergence.

All code and hyperparameters may be found at: https://github.com/openai/improved_gan

Related work

Several recent papers focus on improving the stability of training and the resulting perceptual quality of GAN samples . We build on some of these techniques in this work. For instance, we use some of the “DCGAN” architectural innovations proposed in Radford et al. , as discussed below.

One of our proposed techniques, feature matching, discussed in Sec. 3.1, is similar in spirit to approaches that use maximum mean discrepancy to train generator networks . Another of our proposed techniques, minibatch features, is based in part on ideas used for batch normalization , while our proposed virtual batch normalization is a direct extension of batch normalization.

One of the primary goals of this work is to improve the effectiveness of generative adversarial networks for semi-supervised learning (improving the performance of a supervised task, in this case, classification, by learning on additional unlabeled examples). Like many deep generative models, GANs have previously been applied to semi-supervised learning , and our work can be seen as a continuation and refinement of this effort.

Toward Convergent GAN Training

Training GANs consists in finding a Nash equilibrium to a two-player non-cooperative game. Each player wishes to minimize its own cost function, J(D)(θ(D),θ(G))J^{(D)}({\bm{\theta}}^{(D)},{\bm{\theta}}^{(G)}) for the discriminator and J(G)(θ(D),θ(G))J^{(G)}({\bm{\theta}}^{(D)},{\bm{\theta}}^{(G)}) for the generator. A Nash equilibirum is a point (θ(D),θ(G))({\bm{\theta}}^{(D)},{\bm{\theta}}^{(G)}) such that J(D)J^{(D)} is at a minimum with respect to θ(D){\bm{\theta}}^{(D)} and J(G)J^{(G)} is at a minimum with respect to θ(G){\bm{\theta}}^{(G)}. Unfortunately, finding Nash equilibria is a very difficult problem. Algorithms exist for specialized cases, but we are not aware of any that are feasible to apply to the GAN game, where the cost functions are non-convex, the parameters are continuous, and the parameter space is extremely high-dimensional.

The idea that a Nash equilibrium occurs when each player has minimal cost seems to intuitively motivate the idea of using traditional gradient-based minimization techniques to minimize each player’s cost simultaneously. Unfortunately, a modification to θ(D){\bm{\theta}}^{(D)} that reduces J(D)J^{(D)} can increase J(G)J^{(G)}, and a modification to θ(G){\bm{\theta}}^{(G)} that reduces J(G)J^{(G)} can increase J(D)J^{(D)}. Gradient descent thus fails to converge for many games. For example, when one player minimizes xyxy with respect to xx and another player minimizes xy-xy with respect to yy, gradient descent enters a stable orbit, rather than converging to x=y=0x=y=0, the desired equilibrium point . Previous approaches to GAN training have thus applied gradient descent on each player’s cost simultaneously, despite the lack of guarantee that this procedure will converge. We introduce the following techniques that are heuristically motivated to encourage convergence:

Feature matching addresses the instability of GANs by specifying a new objective for the generator that prevents it from overtraining on the current discriminator. Instead of directly maximizing the output of the discriminator, the new objective requires the generator to generate data that matches the statistics of the real data, where we use the discriminator only to specify the statistics that we think are worth matching. Specifically, we train the generator to match the expected value of the features on an intermediate layer of the discriminator. This is a natural choice of statistics for the generator to match, since by training the discriminator we ask it to find those features that are most discriminative of real data versus data generated by the current model.

2 Minibatch discrimination

One of the main failure modes for GAN is for the generator to collapse to a parameter setting where it always emits the same point. When collapse to a single mode is imminent, the gradient of the discriminator may point in similar directions for many similar points. Because the discriminator processes each example independently, there is no coordination between its gradients, and thus no mechanism to tell the outputs of the generator to become more dissimilar to each other. Instead, all outputs race toward a single point that the discriminator currently believes is highly realistic. After collapse has occurred, the discriminator learns that this single point comes from the generator, but gradient descent is unable to separate the identical outputs. The gradients of the discriminator then push the single point produced by the generator around space forever, and the algorithm cannot converge to a distribution with the correct amount of entropy. An obvious strategy to avoid this type of failure is to allow the discriminator to look at multiple data examples in combination, and perform what we call minibatch discrimination.

The output o(xi)o(x_{i}) for this minibatch layer for a sample xi{\bm{x}}_{i} is then defined as the sum of the cb(xi,xj)c_{b}({\bm{x}}_{i},{\bm{x}}_{j})’s to all other samples:

Next, we concatenate the output o(xi)o({\bm{x}}_{i}) of the minibatch layer with the intermediate features f(xi)\mathbf{f}({\bm{x}}_{i}) that were its input, and we feed the result into the next layer of the discriminator. We compute these minibatch features separately for samples from the generator and from the training data. As before, the discriminator is still required to output a single number for each example indicating how likely it is to come from the training data: The task of the discriminator is thus effectively still to classify single examples as real data or generated data, but it is now able to use the other examples in the minibatch as side information. Minibatch discrimination allows us to generate visually appealing samples very quickly, and in this regard it is superior to feature matching (Section 6). Interestingly, however, feature matching was found to work much better if the goal is to obtain a strong classifier using the approach to semi-supervised learning described in Section 5.

3 Historical averaging

When applying this technique, we modify each player’s cost to include a term θ1ti=1tθ[i]2||{\bm{\theta}}-\frac{1}{t}\sum_{i=1}^{t}{\bm{\theta}}[i]||^{2}, where θ[i]{\bm{\theta}}[i] is the value of the parameters at past time ii. The historical average of the parameters can be updated in an online fashion so this learning rule scales well to long time series. This approach is loosely inspired by the fictitious play algorithm that can find equilibria in other kinds of games. We found that our approach was able to find equilibria of low-dimensional, continuous non-convex games, such as the minimax game with one player controlling xx, the other player controlling yy, and value function (f(x)1)(y1)(f(x)-1)(y-1), where f(x)=xf(x)=x for x<0x<0 and f(x)=x2f(x)=x^{2} otherwise. For these same toy games, gradient descent fails by going into extended orbits that do not approach the equilibrium point.

4 One-sided label smoothing

Label smoothing, a technique from the 1980s recently independently re-discovered by Szegedy et. al , replaces the and 11 targets for a classifier with smoothed values, like .9.9 or .1.1, and was recently shown to reduce the vulnerability of neural networks to adversarial examples .

Replacing positive classification targets with α\alpha and negative targets with β\beta, the optimal discriminator becomes D(x)=αpdata(x)+βpmodel(x)pdata(x)+pmodel(x)D({\bm{x}})=\frac{\alpha p_{\rm{data}}({\bm{x}})+\beta p_{\rm{model}}({\bm{x}})}{p_{\rm{data}}({\bm{x}})+p_{\rm{model}}({\bm{x}})}. The presence of pmodelp_{\rm{model}} in the numerator is problematic because, in areas where pdatap_{\rm{data}} is approximately zero and pmodelp_{\rm{model}} is large, erroneous samples from pmodelp_{\rm{model}} have no incentive to move nearer to the data. We therefore smooth only the positive labels to α\alpha, leaving negative labels set to 0.

5 Virtual batch normalization

Batch normalization greatly improves optimization of neural networks, and was shown to be highly effective for DCGANs . However, it causes the output of a neural network for an input example x{\bm{x}} to be highly dependent on several other inputs x{\bm{x}}^{\prime} in the same minibatch. To avoid this problem we introduce virtual batch normalization (VBN), in which each example x{\bm{x}} is normalized based on the statistics collected on a reference batch of examples that are chosen once and fixed at the start of training, and on x{\bm{x}} itself. The reference batch is normalized using only its own statistics. VBN is computationally expensive because it requires running forward propagation on two minibatches of data, so we use it only in the generator network.

Assessment of image quality

Generative adversarial networks lack an objective function, which makes it difficult to compare performance of different models. One intuitive metric of performance can be obtained by having human annotators judge the visual quality of samples . We automate this process using Amazon Mechanical Turk (MTurk), using the web interface in figure Fig. 2 (live at http://infinite-chamber-35121.herokuapp.com/cifar-minibatch/), which we use to ask annotators to distinguish between generated data and real data. The resulting quality assessments of our models are described in Section 6.

A downside of using human annotators is that the metric varies depending on the setup of the task and the motivation of the annotators. We also find that results change drastically when we give annotators feedback about their mistakes: By learning from such feedback, annotators are better able to point out the flaws in generated images, giving a more pessimistic quality assessment. The left column of Fig. 2 presents a screen from the annotation process, while the right column shows how we inform annotators about their mistakes.

Semi-supervised learning

Consider a standard classifier for classifying a data point x{\bm{x}} into one of KK possible classes. Such a model takes in x{\bm{x}} as input and outputs a KK-dimensional vector of logits {l1,,lK}\{l_{1},\dots,l_{K}\}, that can be turned into class probabilities by applying the softmax: pmodel(y=jx)=exp(lj)k=1Kexp(lk)p_{\text{model}}(y=j|{\bm{x}})=\frac{\exp(l_{j})}{\sum_{k=1}^{K}\exp(l_{k})}. In supervised learning, such a model is then trained by minimizing the cross-entropy between the observed labels and the model predictive distribution pmodel(yx)p_{\text{model}}(y|{\bm{x}}).

We can do semi-supervised learning with any standard classifier by simply adding samples from the GAN generator GG to our data set, labeling them with a new “generated” class y=K+1y=K+1, and correspondingly increasing the dimension of our classifier output from KK to K+1K+1. We may then use pmodel(y=K+1x)p_{\rm{model}}(y=K+1\mid{\bm{x}}) to supply the probability that x{\bm{x}} is fake, corresponding to 1D(x)1-D({\bm{x}}) in the original GAN framework. We can now also learn from unlabeled data, as long as we know that it corresponds to one of the KK classes of real data by maximizing logpmodel(y{1,,K}x)\log p_{\text{model}}(y\in\{1,\ldots,K\}|{\bm{x}}). Assuming half of our data set consists of real data and half of it is generated (this is arbitrary), our loss function for training the classifier then becomes

where we have decomposed the total cross-entropy loss into our standard supervised loss function LsupervisedL_{\text{supervised}} (the negative log probability of the label, given that the data is real) and an unsupervised loss LunsupervisedL_{\text{unsupervised}} which is in fact the standard GAN game-value as becomes evident when we substitute D(x)=1pmodel(y=K+1x)D({\bm{x}})=1-p_{\text{model}}(y=K+1|{\bm{x}}) into the expression:

The optimal solution for minimizing both LsupervisedL_{\text{supervised}} and LunsupervisedL_{\text{unsupervised}} is to have exp[lj(x)]=c(x)p(y=j,x)j<K+1\exp[l_{j}({\bm{x}})]=c({\bm{x}})p(y{=}j,{\bm{x}})\forall j{<}K{+}1 and exp[lK+1(x)]=c(x)pG(x)\exp[l_{K+1}({\bm{x}})]=c({\bm{x}})p_{G}({\bm{x}}) for some undetermined scaling function c(x)c({\bm{x}}). The unsupervised loss is thus consistent with the supervised loss in the sense of Sutskever et al. , and we can hope to better estimate this optimal solution from the data by minimizing these two loss functions jointly. In practice, LunsupervisedL_{\text{unsupervised}} will only help if it is not trivial to minimize for our classifier and we thus need to train GG to approximate the data distribution. One way to do this is by training GG to minimize the GAN game-value, using the discriminator DD defined by our classifier. This approach introduces an interaction between GG and our classifier that we do not fully understand yet, but empirically we find that optimizing GG using feature matching GAN works very well for semi-supervised learning, while training GG using GAN with minibatch discrimination does not work at all. Here we present our empirical results using this approach; developing a full theoretical understanding of the interaction between DD and GG using this approach is left for future work.

Finally, note that our classifier with K+1K+1 outputs is over-parameterized: subtracting a general function f(x)f({\bm{x}}) from each output logit, i.e. setting lj(x)lj(x)f(x)jl_{j}({\bm{x}})\leftarrow l_{j}({\bm{x}})-f({\bm{x}})\forall j, does not change the output of the softmax. This means we may equivalently fix lK+1(x)=0xl_{K+1}({\bm{x}})=0\forall{\bm{x}}, in which case LsupervisedL_{\text{supervised}} becomes the standard supervised loss function of our original classifier with K classes, and our discriminator DD is given by D(x)=Z(x)Z(x)+1, where Z(x)=k=1Kexp[lk(x)]D({\bm{x}})=\frac{Z({\bm{x}})}{Z({\bm{x}})+1},\text{ where }Z({\bm{x}})=\sum_{k=1}^{K}\exp[l_{k}({\bm{x}})].

Besides achieving state-of-the-art results in semi-supervised learning, the approach described above also has the surprising effect of improving the quality of generated images as judged by human annotators. The reason appears to be that the human visual system is strongly attuned to image statistics that can help infer what class of object an image represents, while it is presumably less sensitive to local statistics that are less important for interpretation of the image. This is supported by the high correlation we find between the quality reported by human annotators and the Inception score we developed in Section 4, which is explicitly constructed to measure the “objectness” of a generated image. By having the discriminator DD classify the object shown in the image, we bias it to develop an internal representation that puts emphasis on the same features humans emphasize. This effect can be understood as a method for transfer learning, and could potentially be applied much more broadly. We leave further exploration of this possibility for future work.

Experiments

We performed semi-supervised experiments on MNIST, CIFAR-10 and SVHN, and sample generation experiments on MNIST, CIFAR-10, SVHN and ImageNet. We provide code to reproduce the majority of our experiments.

The MNIST dataset contains 60,00060,000 labeled images of digits. We perform semi-supervised training with a small randomly picked fraction of these, considering setups with 2020, 5050, 100100, and 200200 labeled examples. Results are averaged over 1010 random subsets of labeled data, each chosen to have a balanced number of examples from each class. The remaining training images are provided without labels. Our networks have 5 hidden layers each. We use weight normalization and add Gaussian noise to the output of each layer of the discriminator. Table 1 summarizes our results.

Samples generated by the generator during semi-supervised learning using feature matching (Section 3.1) do not look visually appealing (left Fig. 3). By using minibatch discrimination instead (Section 3.2) we can improve their visual quality. On MTurk, annotators were able to distinguish samples in 52.4%52.4\% of cases (20002000 votes total), where 50%50\% would be obtained by random guessing. Similarly, researchers in our institution were not able to find any artifacts that would allow them to distinguish samples. However, semi-supervised learning with minibatch discrimination does not produce as good a classifier as does feature matching.

2 CIFAR-10

CIFAR-10 is a small, well studied dataset of 32×3232\times 32 natural images. We use this data set to study semi-supervised learning, as well as to examine the visual quality of samples that can be achieved. For the discriminator in our GAN we use a 99 layer deep convolutional network with dropout and weight normalization. The generator is a 4 layer deep CNN with batch normalization. Table 2 summarizes our results on the semi-supervised learning task.

When presented with 50%50\% real and 50%50\% fake data generated by our best CIFAR-10 model, MTurk users correctly categorized 78.7%78.7\% of images correctly. However, MTurk users may not be sufficiently familiar with CIFAR-10 images or sufficiently motivated; we ourselves were able to categorize images with >95%>95\% accuracy. We validated the Inception score described above by observing that MTurk accuracy drops to 71.4%71.4\% when the data is filtered by using only the top 1%1\% of samples according to the Inception score. We performed a series of ablation experiments to demonstrate that our proposed techniques improve the Inception score, presented in Table 3. We also present images for these ablation experiments—in our opinion, the Inception score correlates well with our subjective judgment of image quality. Samples from the dataset achieve the highest value. All the models that even partially collapse have relatively low scores. We caution that the Inception score should be used as a rough guide to evaluate models that were trained via some independent criterion; directly optimizing Inception score will lead to the generation of adversarial examples .

3 SVHN

For the SVHN data set, we used the same architecture and experimental setup as for CIFAR-10.

4 ImageNet

We tested our techniques on a dataset of unprecedented scale: 128×128128\times 128 images from the ILSVRC2012 dataset with 1,000 categories. To our knowledge, no previous publication has applied a generative model to a dataset with both this large of a resolution and this large a number of object classes. The large number of object classes is particularly challenging for GANs due to their tendency to underestimate the entropy in the distribution. We extensively modified a publicly available implementation of DCGANshttps://github.com/carpedm20/DCGAN-tensorflow using TensorFlow to achieve high performance, using a multi-GPU implementation. DCGANs without modification learn some basic image statistics and generate contiguous shapes with somewhat natural color and texture but do not learn any objects. Using the techniques described in this paper, GANs learn to generate objects that resemble animals, but with incorrect anatomy. Results are shown in Fig. 6.

Conclusion

Generative adversarial networks are a promising class of generative models that has so far been held back by unstable training and by the lack of a proper evaluation metric. This work presents partial solutions to both of these problems. We propose several techniques to stabilize training that allow us to train models that were previously untrainable. Moreover, our proposed evaluation metric (the Inception score) gives us a basis for comparing the quality of these models. We apply our techniques to the problem of semi-supervised learning, achieving state-of-the-art results on a number of different data sets in computer vision. The contributions made in this work are of a practical nature; we hope to develop a more rigorous theoretical understanding in future work.

References