Generative Modeling by Estimating Gradients of the Data Distribution

Yang Song, Stefano Ermon

Introduction

Generative models have many applications in machine learning. To list a few, they have been used to generate high-fidelity images , synthesize realistic speech and music fragments , improve the performance of semi-supervised learning , detect adversarial examples and other anomalous data , imitation learning , and explore promising states in reinforcement learning . Recent progress is mainly driven by two approaches: likelihood-based methods and generative adversarial networks (GAN ). The former uses log-likelihood (or a suitable surrogate) as the training objective, while the latter uses adversarial training to minimize ff-divergences or integral probability metrics between model and data distributions.

Although likelihood-based models and GANs have achieved great success, they have some intrinsic limitations. For example, likelihood-based models either have to use specialized architectures to build a normalized probability model (e.g., autoregressive models, flow models), or use surrogate losses (e.g., the evidence lower bound used in variational auto-encoders , contrastive divergence in energy-based models ) for training. GANs avoid some of the limitations of likelihood-based models, but their training can be unstable due to the adversarial training procedure. In addition, the GAN objective is not suitable for evaluating and comparing different GAN models. While other objectives exist for generative modeling, such as noise contrastive estimation and minimum probability flow , these methods typically only work well for low-dimensional data.

In this paper, we explore a new principle for generative modeling based on estimating and sampling from the (Stein) score of the logarithmic data density, which is the gradient of the log-density function at the input data point. This is a vector field pointing in the direction where the log data density grows the most. We use a neural network trained with score matching to learn this vector field from data. We then produce samples using Langevin dynamics, which approximately works by gradually moving a random initial sample to high density regions along the (estimated) vector field of scores. However, there are two main challenges with this approach. First, if the data distribution is supported on a low dimensional manifold—as it is often assumed for many real world datasets—the score will be undefined in the ambient space, and score matching will fail to provide a consistent score estimator. Second, the scarcity of training data in low data density regions, e.g., far from the manifold, hinders the accuracy of score estimation and slows down the mixing of Langevin dynamics sampling. Since Langevin dynamics will often be initialized in low-density regions of the data distribution, inaccurate score estimation in these regions will negatively affect the sampling process. Moreover, mixing can be difficult because of the need of traversing low density regions to transition between modes of the distribution.

To tackle these two challenges, we propose to perturb the data with random Gaussian noise of various magnitudes. Adding random noise ensures the resulting distribution does not collapse to a low dimensional manifold. Large noise levels will produce samples in low density regions of the original (unperturbed) data distribution, thus improving score estimation. Crucially, we train a single score network conditioned on the noise level and estimate the scores at all noise magnitudes. We then propose an annealed version of Langevin dynamics, where we initially use scores corresponding to the highest noise level, and gradually anneal down the noise level until it is small enough to be indistinguishable from the original data distribution. Our sampling strategy is inspired by simulated annealing which heuristically improves optimization for multimodal landscapes.

Our approach has several desirable properties. First, our objective is tractable for almost all parameterizations of the score networks without the need of special constraints or architectures, and can be optimized without adversarial training, MCMC sampling, or other approximations during training. The objective can also be used to quantitatively compare different models on the same dataset. Experimentally, we demonstrate the efficacy of our approach on MNIST, CelebA , and CIFAR-10 . We show that the samples look comparable to those generated from modern likelihood-based models and GANs. On CIFAR-10, our model sets the new state-of-the-art inception score of 8.87 for unconditional generative models, and achieves a competitive FID score of 25.32. We show that the model learns meaningful representations of the data by image inpainting experiments.

Score-based generative modeling

where xsθ(x)\nabla_{\mathbf{x}}\mathbf{s}_{\boldsymbol{\theta}}(\mathbf{x}) denotes the Jacobian of sθ(x)\mathbf{s}_{\boldsymbol{\theta}}(\mathbf{x}). As shown in , under some regularity conditions the minimizer of Eq. (3) (denoted as sθ(x)\mathbf{s}_{{\boldsymbol{\theta}}^{*}}(\mathbf{x})) satisfies sθ(x)=xlogpdata(x)\mathbf{s}_{{\boldsymbol{\theta}}^{*}}(\mathbf{x})=\nabla_{\mathbf{x}}\log p_{\text{data}}(\mathbf{x}) almost surely. In practice, the expectation over pdata(x)p_{\text{data}}(\mathbf{x}) in Eq. (1) can be quickly estimated using data samples. However, score matching is not scalable to deep networks and high dimensional data due to the computation of tr(xsθ(x))\operatorname{tr}(\nabla_{\mathbf{x}}\mathbf{s}_{\boldsymbol{\theta}}(\mathbf{x})). Below we discuss two popular methods for large scale score matching.

As shown in , the optimal score network (denoted as sθ(x)\mathbf{s}_{{\boldsymbol{\theta}}^{*}}(\mathbf{x})) that minimizes Eq. (2) satisfies sθ(x)=xlogqσ(x)\mathbf{s}_{{\boldsymbol{\theta}}^{*}}(\mathbf{x})=\nabla_{\mathbf{x}}\log q_{\sigma}(\mathbf{x}) almost surely. However, sθ(x)=xlogqσ(x)xlogpdata(x)\mathbf{s}_{{\boldsymbol{\theta}}^{*}}(\mathbf{x})=\nabla_{\mathbf{x}}\log q_{\sigma}(\mathbf{x})\approx\nabla_{\mathbf{x}}\log p_{\text{data}}(\mathbf{x}) is true only when the noise is small enough such that qσ(x)pdata(x)q_{\sigma}(\mathbf{x})\approx p_{\text{data}}(\mathbf{x}).

Sliced score matching uses random projections to approximate tr(xsθ(x))\operatorname{tr}(\nabla_{\mathbf{x}}\mathbf{s}_{\boldsymbol{\theta}}(\mathbf{x})) in score matching. The objective is

where pvp_{\mathbf{v}} is a simple distribution of random vectors, e.g., the multivariate standard normal. As shown in , the term vxsθ(x)v\mathbf{v}^{\intercal}\nabla_{\mathbf{x}}\mathbf{s}_{\boldsymbol{\theta}}(\mathbf{x})\mathbf{v} can be efficiently computed by forward mode auto-differentiation. Unlike denoising score matching which estimates the scores of perturbed data, sliced score matching provides score estimation for the original unperturbed data distribution, but requires around four times more computations due to the forward mode auto-differentiation.

2 Sampling with Langevin dynamics

Note that sampling from Eq. (4) only requires the score function xlogp(x)\nabla_{\mathbf{x}}\log p(\mathbf{x}). Therefore, in order to obtain samples from pdata(x)p_{\text{data}}(\mathbf{x}), we can first train our score network such that sθ(x)xlogpdata(x)\mathbf{s}_{\boldsymbol{\theta}}(\mathbf{x})\approx\nabla_{\mathbf{x}}\log p_{\text{data}}(\mathbf{x}) and then approximately obtain samples with Langevin dynamics using sθ(x)\mathbf{s}_{\boldsymbol{\theta}}(\mathbf{x}). This is the key idea of our framework of score-based generative modeling.

Challenges of score-based generative modeling

In this section, we analyze more closely the idea of score-based generative modeling. We argue that there are two major obstacles that prevent a naïve application of this idea.

The manifold hypothesis states that data in the real world tend to concentrate on low dimensional manifolds embedded in a high dimensional space (a.k.a., the ambient space). This hypothesis empirically holds for many datasets, and has become the foundation of manifold learning . Under the manifold hypothesis, score-based generative models will face two key difficulties. First, since the score xlogpdata(x)\nabla_{\mathbf{x}}\log p_{\text{data}}(\mathbf{x}) is a gradient taken in the ambient space, it is undefined when x\mathbf{x} is confined to a low dimensional manifold. Second, the score matching objective Eq. (1) provides a consistent score estimator only when the support of the data distribution is the whole space (cf., Theorem 2 in ), and will be inconsistent when the data reside on a low-dimensional manifold.

2 Low data density regions

The scarcity of data in low density regions can cause difficulties for both score estimation with score matching and MCMC sampling with Langevin dynamics.

To demonstrate the negative effect of this, we provide the result of a toy experiment (details in Appendix B.1) in Fig. 2 where we use sliced score matching to estimate scores of a mixture of Gaussians pdata=15N((5,5),I)+45N((5,5),I)p_{\text{data}}=\frac{1}{5}\mathcal{N}((-5,-5),I)+\frac{4}{5}\mathcal{N}((5,5),I). As the figure demonstrates, score estimation is only reliable in the immediate vicinity of the modes of pdatap_{\text{data}}, where the data density is high.

2.2 Slow mixing of Langevin dynamics

When two modes of the data distribution are separated by low density regions, Langevin dynamics will not be able to correctly recover the relative weights of these two modes in reasonable time, and therefore might not converge to the true distribution. Our analyses of this are largely inspired by , which analyzed the same phenomenon in the context of density estimation with score matching.

Consider a mixture distribution pdata(x)=πp1(x)+(1π)p2(x)p_{\text{data}}(\mathbf{x})=\pi p_{1}(\mathbf{x})+(1-\pi)p_{2}(\mathbf{x}), where p1(x)p_{1}(\mathbf{x}) and p2(x)p_{2}(\mathbf{x}) are normalized distributions with disjoint supports, and π(0,1)\pi\in(0,1). In the support of p1(x)p_{1}(\mathbf{x}), xlogpdata(x)=x(logπ+logp1(x))=xlogp1(x)\nabla_{\mathbf{x}}\log p_{\text{data}}(\mathbf{x})=\nabla_{\mathbf{x}}(\log\pi+\log p_{1}(\mathbf{x}))=\nabla_{\mathbf{x}}\log p_{1}(\mathbf{x}), and in the support of p2(x)p_{2}(\mathbf{x}), xlogpdata(x)=x(log(1π)+logp2(x))=xlogp2(x)\nabla_{\mathbf{x}}\log p_{\text{data}}(\mathbf{x})=\nabla_{\mathbf{x}}(\log(1-\pi)+\log p_{2}(\mathbf{x}))=\nabla_{\mathbf{x}}\log p_{2}(\mathbf{x}). In either case, the score xlogpdata(x)\nabla_{\mathbf{x}}\log p_{\text{data}}(\mathbf{x}) does not depend on π\pi. Since Langevin dynamics use xlogpdata(x)\nabla_{\mathbf{x}}\log p_{\text{data}}(\mathbf{x}) to sample from pdata(x)p_{\text{data}}(\mathbf{x}), the samples obtained will not depend on π\pi. In practice, this analysis also holds when different modes have approximately disjoint supports—they may share the same support but be connected by regions of small data density. In this case, Langevin dynamics can produce correct samples in theory, but may require a very small step size and a very large number of steps to mix.

To verify this analysis, we test Langevin dynamics sampling for the same mixture of Gaussian used in Section 3.2.1 and provide the results in Fig. 3. We use the ground truth scores when sampling with Langevin dynamics. Comparing Fig. 3(b) with (a), it is obvious that the samples from Langevin dynamics have incorrect relative density between the two modes, as predicted by our analysis.

Noise Conditional Score Networks: learning and inference

We observe that perturbing data with random Gaussian noise makes the data distribution more amenable to score-based generative modeling. First, since the support of our Gaussian noise distribution is the whole space, the perturbed data will not be confined to a low dimensional manifold, which obviates difficulties from the manifold hypothesis and makes score estimation well-defined. Second, large Gaussian noise has the effect of filling low density regions in the original unperturbed data distribution; therefore score matching may get more training signal to improve score estimation. Furthermore, by using multiple noise levels we can obtain a sequence of noise-perturbed distributions that converge to the true data distribution. We can improve the mixing rate of Langevin dynamics on multimodal distributions by leveraging these intermediate distributions in the spirit of simulated annealing and annealed importance sampling .

Built upon this intuition, we propose to improve score-based generative modeling by 1) perturbing the data using various levels of noise; and 2) simultaneously estimating scores corresponding to all noise levels by training a single conditional score network. After training, when using Langevin dynamics to generate samples, we initially use scores corresponding to large noise, and gradually anneal down the noise level. This helps smoothly transfer the benefits of large noise levels to low noise levels where the perturbed data are almost indistinguishable from the original ones. In what follows, we will elaborate more on the details of our method, including the architecture of our score networks, the training objective, and the annealing schedule for Langevin dynamics.

Similar to likelihood-based generative models and GANs, the design of model architectures plays an important role in generating high quality samples. In this work, we mostly focus on architectures useful for image generation, and leave the architecture design for other domains as future work. Since the output of our noise conditional score network sθ(x,σ)\mathbf{s}_{\boldsymbol{\theta}}(\mathbf{x},\sigma) has the same shape as the input image x\mathbf{x}, we draw inspiration from successful model architectures for dense prediction of images (e.g., semantic segmentation). In the experiments, our model sθ(x,σ)\mathbf{s}_{\boldsymbol{\theta}}(\mathbf{x},\sigma) combines the architecture design of U-Net with dilated/atrous convolution —both of which have been proved very successful in semantic segmentation. In addition, we adopt instance normalization in our score network, inspired by its superior performance in some image generation tasks , and we use a modified version of conditional instance normalization to provide conditioning on σi\sigma_{i}. More details on our architecture can be found in Appendix A.

2 Learning NCSNs via score matching

Then, we combine Eq. (5) for all σ{σi}i=1L\sigma\in\{\sigma_{i}\}_{i=1}^{L} to get one unified objective

where λ(σi)>0\lambda(\sigma_{i})>0 is a coefficient function depending on σi\sigma_{i}. Assuming sθ(x,σ)\mathbf{s}_{\boldsymbol{\theta}}(\mathbf{x},\sigma) has enough capacity, sθ(x,σ)\mathbf{s}_{{\boldsymbol{\theta}}^{*}}(\mathbf{x},\sigma) minimizes Eq. (6) if and only if sθ(x,σi)=xlogqσi(x)\mathbf{s}_{{\boldsymbol{\theta}}^{*}}(\mathbf{x},\sigma_{i})=\nabla_{\mathbf{x}}\log q_{\sigma_{i}}(\mathbf{x}) a.s. for all i{1,2,,L}i\in\{1,2,\cdots,L\}, because Eq. (6) is a conical combination of LL denoising score matching objectives.

We emphasize that our objective Eq. (6) requires no adversarial training, no surrogate losses, and no sampling from the score network during training (e.g., unlike contrastive divergence). Also, it does not require sθ(x,σ)\mathbf{s}_{\boldsymbol{\theta}}(\mathbf{x},\sigma) to have special architectures in order to be tractable. In addition, when λ()\lambda(\cdot) and {σi}i=1L\{\sigma_{i}\}_{i=1}^{L} are fixed, it can be used to quantitatively compare different NCSNs.

3 NCSN inference via annealed Langevin dynamics

After the NCSN sθ(x,σ)\mathbf{s}_{\boldsymbol{\theta}}(\mathbf{x},\sigma) is trained, we propose a sampling approach—annealed Langevin dynamics (Alg. 1)—to produced samples, inspired by simulated annealing and annealed importance sampling . As shown in Alg. 1, we start annealed Langevin dynamics by initializing the samples from some fixed prior distribution, e.g., uniform noise. Then, we run Langevin dynamics to sample from qσ1(x)q_{\sigma_{1}}(\mathbf{x}) with step size α1\alpha_{1}. Next, we run Langevin dynamics to sample from qσ2(x)q_{\sigma_{2}}(\mathbf{x}), starting from the final samples of the previous simulation and using a reduced step size α2\alpha_{2}. We continue in this fashion, using the final samples of Langevin dynamics for qσi1(x)q_{\sigma_{i-1}}(\mathbf{x}) as the initial samples of Langevin dynamic for qσi(x)q_{\sigma_{i}}(\mathbf{x}), and tuning down the step size αi\alpha_{i} gradually with αi=ϵσi2/σL2\alpha_{i}=\epsilon\cdot\sigma_{i}^{2}/\sigma_{L}^{2}. Finally, we run Langevin dynamics to sample from qσL(x)q_{\sigma_{L}}(\mathbf{x}), which is close to pdata(x)p_{\text{data}}(\mathbf{x}) when σL0\sigma_{L}\approx 0.

Since the distributions {qσi}i=1L\{q_{\sigma_{i}}\}_{i=1}^{L} are all perturbed by Gaussian noise, their supports span the whole space and their scores are well-defined, avoiding difficulties from the manifold hypothesis. When σ1\sigma_{1} is sufficiently large, the low density regions of qσ1(x)q_{\sigma_{1}}(\mathbf{x}) become small and the modes become less isolated. As discussed previously, this can make score estimation more accurate, and the mixing of Langevin dynamics faster. We can therefore assume that Langevin dynamics produce good samples for qσ1(x)q_{\sigma_{1}}(\mathbf{x}). These samples are likely to come from high density regions of qσ1(x)q_{\sigma_{1}}(\mathbf{x}), which means they are also likely to reside in the high density regions of qσ2(x)q_{\sigma_{2}}(\mathbf{x}), given that qσ1(x)q_{\sigma_{1}}(\mathbf{x}) and qσ2(x)q_{\sigma_{2}}(\mathbf{x}) only slightly differ from each other. As score estimation and Langevin dynamics perform better in high density regions, samples from qσ1(x)q_{\sigma_{1}}(\mathbf{x}) will serve as good initial samples for Langevin dynamics of qσ2(x)q_{\sigma_{2}}(\mathbf{x}). Similarly, qσi1(x)q_{\sigma_{i-1}}(\mathbf{x}) provides good initial samples for qσi(x)q_{\sigma_{i}}(\mathbf{x}), and finally we obtain samples of good quality from qσL(x)q_{\sigma_{L}}(\mathbf{x}).

To demonstrate the efficacy of our annealed Langevin dynamics, we provide a toy example where the goal is to sample from a mixture of Gaussian with two well-separated modes using only scores. We apply Alg. 1 to sample from the mixture of Gausssian used in Section 3.2. In the experiment, we choose {σi}i=1L\{\sigma_{i}\}_{i=1}^{L} to be a geometric progression, with L=10L=10, σ1=10\sigma_{1}=10 and σ10=0.1\sigma_{10}=0.1. The results are provided in Fig. 3. Comparing Fig. 3 (b) against (c), annealed Langevin dynamics correctly recover the relative weights between the two modes whereas standard Langevin dynamics fail.

Experiments

In this section, we demonstrate that our NCSNs are able to produce high quality image samples on several commonly used image datasets. In addition, we show that our models learn reasonable image representations by image inpainting experiments.

We use MNIST, CelebA , and CIFAR-10 datasets in our experiments. For CelebA, the images are first center-cropped to 140×140140\times 140 and then resized to 32×3232\times 32. All images are rescaled so that pixel values are in $.Wechoose. We chooseL=10differentstandarddeviationssuchthatdifferent standard deviations such that\{\sigma_{i}\}_{i=1}^{L}isageometricsequencewithis a geometric sequence with\sigma_{1}=1andand\sigma_{10}=0.01.NotethatGaussiannoiseof. Note that Gaussian noise of\sigma=0.01isalmostindistinguishabletohumaneyesforimagedata.WhenusingannealedLangevindynamicsforimagegeneration,wechooseis almost indistinguishable to human eyes for image data. When using annealed Langevin dynamics for image generation, we chooseT=100andand\epsilon=2\times 10^{-5},anduseuniformnoiseasourinitialsamples.Wefoundtheresultsarerobustw.r.t.thechoiceof, and use uniform noise as our initial samples. We found the results are robust w.r.t. the choice ofT,and, and\epsilonbetweenbetween5\times 10^{-6}andand5\times 10^{-5}$ generally works fine. We provide additional details on model architecture and settings in Appendix A and B.

In Fig. 5, we show uncurated samples from annealed Langevin dynamics for MNIST, CelebA and CIFAR-10. As shown by the samples, our generated images have higher or comparable quality to those from modern likelihood-based models and GANs. To intuit the procedure of annealed Langevin dynamics, we provide intermediate samples in Fig. 4, where each row shows how samples evolve from pure random noise to high quality images. More samples from our approach can be found in Appendix C. We also show the nearest neighbors of generated images in the training dataset in Appendix C.2, in order to demonstrate that our model is not simply memorizing training images. To show it is important to learn a conditional score network jointly for many noise levels and use annealed Langevin dynamics, we compare against a baseline approach where we only consider one noise level {σ1=0.01}\{\sigma_{1}=0.01\} and use the vanilla Langevin dynamics sampling method. Although this small added noise helps circumvent the difficulty of the manifold hypothesis (as shown by Fig. 1, things will completely fail if no noise is added), it is not large enough to provide information on scores in regions of low data density. As a result, this baseline fails to generate reasonable images, as shown by samples in Appendix C.1.

For quantitative evaluation, we report inception and FID scores on CIFAR-10 in Tab. 1. As an unconditional model, we achieve the state-of-the-art inception score of 8.87, which is even better than most reported values for class-conditional generative models. Our FID score 25.32 on CIFAR-10 is also comparable to top existing models, such as SNGAN . We omit scores on MNIST and CelebA as the scores on these two datasets are not widely reported, and different preprocessing (such as the center crop size of CelebA) can lead to numbers not directly comparable.

In Fig. 6, we demonstrate that our score networks learn generalizable and semantically meaningful image representations that allow it to produce diverse image inpaintings. Note that some previous models such as PixelCNN can only impute images in the raster scan order. In contrast, our method can naturally handle images with occlusions of arbitrary shapes by a simple modification of the annealed Langevin dynamics procedure (details in Appendix B.3). We provide more image inpainting results in Appendix C.5.

Related work

Our approach has some similarities with methods that learn the transition operator of a Markov chain for sample generation . For example, generative stochastic networks (GSN ) use denoising autoencoders to train a Markov chain whose equilibrium distribution matches the data distribution. Similarly, our method trains the score function used in Langevin dynamics to sample from the data distribution. However, GSN often starts the chain very close to a training data point, and therefore requires the chain to transition quickly between different modes. In contrast, our annealed Langevin dynamics are initialized from unstructured noise. Nonequilibrium Thermodynamics (NET ) used a prescribed diffusion process to slowly transform data into random noise, and then learned to reverse this procedure by training an inverse diffusion. However, NET is not very scalable because it requires the diffusion process to have very small steps, and needs to simulate chains with thousands of steps at training time.

Previous approaches such as Infusion Training (IT ) and Variational Walkback (VW ) also employed different noise levels/temperatures for training transition operators of a Markov chain. Both IT and VW (as well as NET) train their models by maximizing the evidence lower bound of a suitable marginal likelihood. In practice, they tend to produce blurry image samples, similar to variational autoencoders. In contrast, our objective is based on score matching instead of likelihood, and we can produce images comparable to GANs.

There are several structural differences that further distinguish our approach from previous methods discussed above. First, we do not need to sample from a Markov chain during training. In contrast, the walkback procedure of GSNs needs multiple runs of the chain to generate “negative samples”. Other methods including NET, IT, and VW also need to simulate a Markov chain for every input to compute the training loss. This difference makes our approach more efficient and scalable for training deep models. Secondly, our training and sampling methods are decoupled from each other. For score estimation, both sliced and denoising score matching can be used. For sampling, any method based on scores is applicable, including Langevin dynamics and (potentially) Hamiltonian Monte Carlo . Our framework allows arbitrary combinations of score estimators and (gradient-based) sampling approaches, whereas most previous methods tie the model to a specific Markov chain. Finally, our approach can be used to train energy-based models (EBM) by using the gradient of an energy-based model as the score model. In contrast, it is unclear how previous methods that learn transition operators of Markov chains can be directly used for training EBMs.

Score matching was originally proposed for learning EBMs. However, many existing methods based on score matching are either not scalable or fail to produce samples of comparable quality to VAEs or GANs . To obtain better performance on training deep energy-based models, some recent works have resorted to contrastive divergence , and propose to sample with Langevin dynamics for both training and testing . However, unlike our approach, contrastive divergence uses the computationally expensive procedure of Langevin dynamics as an inner loop during training. The idea of combining annealing with denoising score matching has also been investigated in previous work under different contexts. In , different annealing schedules on the noise for training denoising autoencoders are proposed. However, their work is on learning representations for improving the performance of classification, instead of generative modeling. The method of denoising score matching can also be derived from the perspective of Bayes least squares , using techniques of Stein’s Unbiased Risk Estimator .

Conclusion

We propose the framework of score-based generative modeling where we first estimate gradients of data densities via score matching, and then generate samples via Langevin dynamics. We analyze several challenges faced by a naïve application of this approach, and propose to tackle them by training Noise Conditional Score Networks (NCSN) and sampling with annealed Langevin dynamics. Our approach requires no adversarial training, no MCMC sampling during training, and no special model architectures. Experimentally, we show that our approach can generate high quality images that were previously only produced by the best likelihood-based models and GANs. We achieve the new state-of-the-art inception score on CIFAR-10, and an FID score comparable to SNGANs.

Toyota Research Institute ("TRI") provided funds to assist the authors with their research but this article solely reflects the opinions and conclusions of its authors and not TRI or any other Toyota entity. This research was also supported by NSF (#1651565, #1522054, #1733686), ONR (N00014-19-1-2145), AFOSR (FA9550-19-1-0024).

References

Appendix A Architectures

The architecture of our NCSNs used in the experiments has three important components: instance normalization, dilated convolutions and U-Net-type architectures. Below we give more background on them and discuss how we modified them to suit our purpose. For more comprehensive details and a reference implementation, we recommend the readers to check our publicly available code base. Our score networks are implemented in PyTorch. Code and checkpoints are available at https://github.com/ermongroup/ncsn.

We use conditional instance normalization so that sθ(x,σ)\mathbf{s}_{\boldsymbol{\theta}}(\mathbf{x},\sigma) takes account of σ\sigma when predicting the scores. In conditional instance normalization, a different set of scales and biases is used for different σ{σi}i=1L\sigma\in\{\sigma_{i}\}_{i=1}^{L}. More specifically, suppose x\mathbf{x} is an input with CC feature maps. Let μk\mu_{k} and sks_{k} denote the mean and standard deviation of the kk-th feature map of x\mathbf{x}, taken along the spatial axes. Conditional instance normalization is achieved by

We abbreviate this modification of conditional instance normalization as CondInstanceNorm++. In our architecture, we add CondInstanceNorm++ before every convolutional layer and pooling layer.

A.2 Dilated convolutions

Dilated convolutions can be used to increase the size of receptive field while maintaining the resolution of feature maps. It has been shown very effective in semantic segmentation because they preserve the location information better using feature maps of larger resolutions. In our architecture design of NCSNs, we use it to replace all the subsampling layers except the first one.

A.3 U-Net architecture

U-Net is an architecture with special skip connections. These skip connections help transfer lower level information in shallow layers to deeper layers of the network. Since the shallower layers often contain low level information such as location and shape, these skip connections help improve the result of semantic segmentation. For building sθ(x,σ)\mathbf{s}_{\boldsymbol{\theta}}(\mathbf{x},\sigma), we use the architecture of RefineNet , a modern variant of U-Net that also incorporates ResNet designs. We refer the readers to for a detailed description of the RefineNet architecture.

In our experiments, we use a 4-cascaded RefineNet. We use pre-activation residual blocks. We remove all batch normalizations in the RefineNet architecture, and replace them with CondInstanceNorm++. We replace the max pooling layers in Refine Blocks with average pooling, as average pooling is reported to produce smoother images for image generation tasks such as style transfer. In addition, we also add CondInstanceNorm++ before each convolution and average pooling in the Refine Blocks, although no normalization is used in the original Refine Blocks. All activation functions are chosen to be ELU. As mentioned previously, we use dilated convolutions to replace the subsampling layers in residual blocks, except the first one. Following the common practice, we increase the dilation by a factor of 2 when proceeding to the next cascade. For CelebA and CIFAR-10 experiments, the number of filters for layers corresponding to the first cascade is 128, while the number of filters for other cascades are doubled. For MNIST experiments, the number of filters are halved.

Appendix B Additional experimental details

For the results in Fig. 1, we train a ResNet with sliced score matching on CIFAR-10. We use pre-activation residual blocks, and the ResNet is structured as an auto-encoder, where the encoder contains 5 residual blocks and the decoder mirrors the architecture of the encoder. The number of filters for each residual block of the encoder part is respectively 32, 64, 64, 128 and 128. The 2nd and 4th residual block of the encoder subsamples the feature maps by a factor of two. We use ELU activations throughout the network. We train the network with 50000 iterations using Adam optimizer and a batch size of 128 and learning rate of 0.001. The experiment was run on one Titan XP GPU.

For the results in Fig. 2, we choose pdata=15N((5,5),I)+45N((5,5),I)p_{\text{data}}=\frac{1}{5}\mathcal{N}((-5,-5),I)+\frac{4}{5}\mathcal{N}((5,5),I). The score network is a 3-layer MLP with 128 hidden units and softplus activation functions. We train the score network with sliced score matching for 10000 iterations with Adam optimizer. The learning rate is 0.001, and the batch size is 128. The experiment was run on an Intel Core i7 GPU with 2.7GHz.

For the results in Fig. 3, we use the same toy distribution pdata=15N((5,5),I)+45N((5,5),I)p_{\text{data}}=\frac{1}{5}\mathcal{N}((-5,-5),I)+\frac{4}{5}\mathcal{N}((5,5),I). We generate 1280 samples for each subfigure of Fig. 3. The initial samples are all uniformly chosen in the square ×\times. For Langevin dynamics, we use T=1000T=1000 and ϵ=0.1\epsilon=0.1. For annealed Langevin dynamics, we use T=100T=100, L=10L=10 and ϵ=0.1\epsilon=0.1. We choose {σi}i=1L\{\sigma_{i}\}_{i=1}^{L} to be a geometric progression, with L=10L=10, σ1=20\sigma_{1}=20 and σ10=1\sigma_{10}=1. Both Langevin methods use the ground-truth data score for sampling. The experiment was run on an Intel Core i7 GPU with 2.7GHz.

B.2 Image generation

During training, we randomly flip the images in CelebA and CIFAR-10. All models are optimized by Adam with learning rate 0.0010.001 for a total of 200000 iterations. The batch size is fixed to 128. We save one checkpoint every 5000 iterations. For MNIST, we choose the last checkpoint at the 200000-th training iteration. For selecting our CIFAR-10 and CelebA models, we generate 1000 images for each checkpoint and choose the one with the smallest FID score computed on these 1000 images. Our image samples and results in Tab. 1 are from these checkpoints. Similar model selection procedures have been used in previous work, such as ProgressiveGAN .

The inception and FID scores are computed using the official code from OpenAI https://github.com/openai/improved-gan/tree/master/inception_score and TTUR authors https://github.com/bioinf-jku/TTUR respectively. The architectures are described in Appendix A. When reporting the numbers in Tab. 1, we compute inception and FID scores based on a total of 50000 samples.

The baseline model uses the same score network. The only difference is that the score network is only conditioned on one noise level {σ1=0.01}\{\sigma_{1}=0.01\}. When sampling using Langevin dynamics, we use ϵ=2×105\epsilon=2\times 10^{-5} and T=1000T=1000.

The models on MNIST were run with one Titan XP GPU, while the models on CelebA and CIFAR-10 used two Titan XP GPUs.

B.3 Image inpainting

We use the following Alg. 2 for image inpainting.

The hyperparameters are the same as those of the annealed Langevin dynamics used for image generation.

Appendix C Samples

C.2 Nearest neighbors

C.3 Extended samples

C.4 Extended intermediate samples from annealed Langevin dynamics

C.5 Extended image inpainting results