Auxiliary Guided Autoregressive Variational Autoencoders
Generative modeling of high-dimensional data is a key problem in machine learning. Successful approaches include latent variable models and autoregressive models. The complementary strengths of these approaches, to model global and local image statistics respectively, suggest hybrid models that encode global image structure into latent variables while autoregressively modeling low level detail. Previous approaches to such hybrid models restrict the capacity of the autoregressive decoder to prevent degenerate models that ignore the latent variables and only rely on autoregressive modeling. Our contribution is a training procedure relying on an auxiliary loss function that controls which information is captured by the latent variables and what is left to the autoregressive decoder. Our approach can leverage arbitrarily powerful autoregressive decoders, achieves state-of-the art quantitative performance among models with latent variables, and generates qualitatively convincing samples.
Unsupervised modeling of complex distributions with unknown structure is a landmark challenge in machine learning. The problem is often studied in the context of learning generative models of the complex high-dimensional distributions of natural image collections. Latent variable approaches can learn disentangled and concise representations of the data , which are useful for compression  and semi-supervised learning [14, 22]. When conditioned on prior information, generative models can be used for a variety of tasks, such as attribute or class-conditional image generation, text and pose-based image generation, image colorization, etc. [26, 20, 23, 6]. Recently significant advances in generative (image) modeling have been made along several lines, including adversarial networks [10, 1], variational autoencoders [16, 24], autoregressive models [21, 23], and non-volume preserving variable transformations .
In our work we seek to combine the merits of two of these lines of work. Variational autoencoders (VAEs) [16, 24] can learn latent variable representations that abstract away from low-level details, but model pixels as conditionally independent given the latent variables. This renders the generative model computationally efficient, but the lack of low-level structure modeling leads to overly smooth and blurry samples. Autoregressive models, such as pixelCNNs , on the other hand, estimate complex translation invariant conditional distributions among pixels. They are effective to model low-level image statistics, and yield state-of-the-art likelihoods on test data . This is in line with the observations of  that low-level image details account for a large part of the likelihood. These autoregressive models, however, do not learn a latent variable representations to support, e.g., semi-supervised learning. The complementary strengths of VAEs and pixelCNNs, modeling global and local image statistics respectively, suggest hybrid approaches combining the strengths of both. Prior work on such hybrid models needed to limit the capacity of the autoregressive decoder to prevent degenerate models that completely ignore the latent variables and rely on autoregressive modeling only [12, 5]. In this paper we describe Auxiliary Guided Autoregressive Variational autoEncoders (AGAVE), an approach to train such hybrid models using an auxiliary loss function that controls which information is captured by the latent variables and what is left to the AR decoder. That removes the need to limit the capacity of the latter. See Figure 1 for a schematic illustration of our approach.
Using high-capacity VAE and autoregressive components allows our models to obtain quantitative results on held-out data that are on par with the state of the art in general, and set a new state of the art among models with latent variables. Our models generate samples with both global coherence and low-level details. See Figure 2 for representative samples of VAE and pixelCNN models.
2 Related work
Generative image modeling has recently taken significant strides forward, leveraging deep neural networks to learn complex density models using a variety of approaches. These include the variational autoencoders and autoregressive models that form the basis of our work, but also generative adversarial networks (GANs) [10, 1] and variable transformation with invertible functions . While GANs produce visually appealing samples, they suffer from mode dropping and their likelihood-free nature prevents measuring how well they model held-out test data. In particular, GANs can only generate samples on a non-linear manifold in the data space with dimension equal to the number of latent variables. In contrast, probabilistic models such as VAEs and autoregressive models generalize to the entire data space, and likelihoods of held-out data can be used for compression, and to quantitatively compare different models. The non-volume preserving (NVP) transformation approach of  chains together invertible transformations to map a basic (e.g. unit Gaussian) prior on the latent space to a complex distribution on the data space. This method offers tractable likelihood evaluation and exact inference, but obtains likelihoods on held-out data below the values reported using state-of-the-art VAE and autoregressive models. Moreover, it is restricted to use latent representations with the same dimensionality as the input data, and is thus difficult to scale to model high-resolution images.
Autoregressive density estimation models, such as pixelCNNs , admit tractable likelihood evaluation, while for variational autoencoders [16, 24] accurate approximations can be obtained using importance sampling . Naively combining powerful pixelCNN decoders in a VAE framework results in a degenerate model which ignores the VAE latent variable structure, as explained through the lens of bits-back coding by . To address this issue, the capacity of the the autoregressive component can be restricted. This can, for example, be achieved by reducing its depth and/or field of view, or by giving the pixelCNN only access to grayscale values, i.e. modeling [5, 12]. This forces the model to leverage the latent variables to model part of the dependencies among the pixels. This approach, however, has two drawbacks. (i) Curbing the capacity of the model is undesirable in unsupervised settings where training data is abundant and overfitting unlikely, and is only a partial solution to the problem. (ii) Balancing what is modeled by the VAE and the pixelCNN by means of architectural design choices requires careful hand-design and tuning of the architectures. This is a tedious process, and a more reliable principle is desirable. To overcome these drawbacks, we propose to instead control what is modeled by the VAE and pixelCNN with an auxiliary loss on the VAE decoder output before it is used to condition the autoregressive decoder. This allows us to “plug in” powerful high-capacity VAE and pixelCNN architectures, and balance what is modeled by each component by means of the auxiliary loss.
In a similar vein,  force pixelCNN models to capture more high-level image aspects using an auxiliary representation of the original image , e.g. a low-resolution version of the original. They learn a pixelCNN for , and a conditional pixelCNN to predict from , possibly using several intermediate representations. This approach forces modeling of more high-level aspects in the intermediate representations, and yields visually more compelling samples.  similarly learn a series of conditional autoregressive models to upsample coarser intermediate latent images. By introducing partial conditional independencies in the model they scale the model to efficiently sample high-resolution images of up to 512512 pixels.  use a recurrent VAE model to produces a sequence of RGB images with increasing detail derived from latent variables associated with each iteration. Like our work, all these models work with intermediate representations in RGB space to learn accurate generative image models.
3 Auxiliary guided autoregressive variational autoencoders
We give a brief overview of variational autoencoders and their limitations in Section 3.1, before we present our approach to learning variational autoencoders with autoregressive decoders in Section 3.2.
3.1 Variational autoencoders
Variational autoencoders [16, 24] learn deep generative latent variable models using two neural networks. The “decoder” network implements a conditional distribution over observations given a latent variable , with parameters . Together with a basic prior on the latent variable , e.g. a unit Gaussian, the generative model on is obtained by marginalizing out the latent variable:
The marginal likelihood can, however, not be optimized directly since the non-linear dependencies in render the integral intractable. To overcome this problem, an “encoder” network is used to compute an approximate posterior distribution , with parameters . The approximate posterior is used to define a variational bound on the data log-likelihood, by subtracting the Kullback-Leibler divergence between the true and approximate posterior:
The decomposition in (3) interprets the bound as the sum of a reconstruction term and a regularization term. The first aims to maximize the expected data log-likelihood given the posterior estimate . The second term prevents from collapsing to a single point, which would be optimal for the first term.
Variational autoencoders typically model the dimensions of as conditionally independent,
for instance using a factored Gaussian or Bernoulli model, see e.g. [16, 15, 26]. The conditional independence assumption makes sampling from the VAE efficient: since the decoder network is evaluated only once for a sample to compute all the conditional distributions , the can then be sampled in parallel.
A result of relying on the latent variables to account for all pixel dependencies, however, is that all low-level variability must also be modeled by the latent variables. Consider, for instance, a picture of a dog, and variants of that image shifted by one or a few pixels, or in a slightly different pose, with a slightly lighter background, or with less saturated colors, etc. If these factors of variability are modeled using latent variables, then these low-level aspects are confounded with latent variables relating to the high-level image content. If the corresponding image variability is not modeled using latent variables, it will be modeled as independent pixel noise. In the latter case, using the mean of as the synthetic image for a given results in blurry samples, since the mean is averaged over the low-level variants of the image. Sampling from to obtain synthetic images, on the other hand, results in images with unrealistic independent pixel noise.
3.2 Autoregressive decoders in variational autoencoders
with , and model the conditional distributions using a (deep) neural network. For image data, PixelCNNs [21, 20] use a scanline pixel ordering, and model the conditional distributions using a convolution neural network. The convolutional filters are masked so as to ensure that the receptive fields only extend to pixels when computing the conditional distribution of .
PixelCNNs can be used as a decoder in a VAE by conditioning on the latent variable in addition to the preceding pixels, leading to a variational bound with a modified reconstruction term:
The regularization term can be interpreted as a “cost” of using the latent variables. To effectively use the latent variables, the approximate posterior must differ from the prior , which increases the KL divergence.
 showed that for loss (6) and a decoder with enough capacity, it is optimal to encode no information about in by setting . To ensure meaningful latent representation learning  and  restrict the capacity of the pixelCNN decoder. In our approach, in contrast, it is always optimal for the autoregressive decoder, regardless of its capacity, to exploit the information on carried by . We rely on two decoders in parallel: the first one reconstructs an auxiliary image from an intermediate representation in a non-autoregressive manner. The auxiliary image can be either simply taken to be the original image (), or a compressed version of it, e.g. with lower resolution or with a coarser color quantization. The second decoder is a conditional autoregressive model that predicts conditioned on. Modeling in a non-autoregressive manner ensures a meaningful representation and renders and dependent, inducing a certain non-zero KL “cost” in (6). The uncertainty on is thus reduced when conditioning on , and there is no longer an advantage in ignoring the latent variable for the autoregressive decoder. We provide a more detailed explanation of why our auxiliary loss ensures a meaningful use of latent variables in powerful decoders in 3.3. To train the model we combine both decoders in a single objective function with a shared encoder network:
Treating and as two variables that are conditionally independent given a shared underlying latent vairable leads to . Summing the lower bounds in Eq. (3) and Eq. (6) of the marginal log-likelihoods of and , and sharing the encoder network, leads to . Larger values of result in valid but less tight lower bounds of the log-likelihoods. Encouraging the variational posterior to be closer to the prior, this leads to less informative latent variable representations.
Sharing the encoder across the two decoders is the key of our approach. The factored auxiliary VAE decoder can only model pixel dependencies by means of the latent variables, which ensures that a meaningful representation is learned. Now, given that the VAE encoder output is informative on the image content, there is no incentive for the autoregressive decoder to ignore the intermediate representation on which it is conditioned. The choice of the regularization parameter and auxiliary image provide two levers to control how much and what type of information should be encoded in the latent variables.
3.3 It is optimal for the autoregressive decoder to use
Combining a VAE with a flexible decoder (for instance an autoregressive one) leads to the latent code being ignored. This problem could be attributed to optimization challenges: at the start of training carries little information about , the KL term pushes the model to set it to the prior to avoid any penalty, and training never recovers from falling into that local minimum.  have proposed extensive explanations showing that the problem goes deeper: if a sufficiently expressive decoder is used, ignoring the latents actually is the optimal behavior. The gist of the argument is based on bits-back coding as follows: given an encoder , a decoder and a prior , can be encoded in a lossless manner using , and can be encoded, also losslessly, using . Once the receiver has decoded , becomes available and a secondary message can be decoded from it. This yields and average code length of:
corresponds to the standard VAE objective. A lower-bound on the expected code length for the data being encoded is given by the Shannon entropy: , which yields:
If is expressive enough, or if is poor enough, the following inequality can be verified:
This is always true in the limit of infinitely expressive autoregressive decoders. In that case, any use of the latents that might decrease performance. The optimal behavior is to set to avoid the extra KL cost. Then becomes independent from and no information about is encoded in .
Therefore, given an encoder, the latent variables will only be used if the capacity of the autoregressive decoder is sufficiently restricted. This is the approach taken by  and . This approach works: it has obtained competitive quantitative and qualitative performance. However, it is not satisfactory in the sense that autoregressive models cannot be used to the full extent of their potential, while learning a meaningful latent variable representation.
In our setting, both have to be sent to and decoded by the receiver. Let us denote the expected code length required to send the auxiliary message, . Once has been sent, sending costs: , and we have:
Using the fact that the Shannon entropy is the optimal expected code length for transmitting , we obtain
The entropy of a random variable decreases when it is conditioned on another, i.e. . Therefore, the theoretical lower-bound on the expected code length in our setup is always better when the autoregressive component takes into account, no matter its expressivity. In the limit case of an infinitely expressive autoregressive decoder, denoted by , the lower bound is attained and In non-degenerate cases, the VAE is optimized to encode information about into a meaningful , with potentially near perfect reconstructions, and there exists such that , making the lower bound stricly better by a possibly big margin.
This analysis shows that in our setup it is theoretically always better for the autoregressive model to make use of the latent and auxiliary representation it is conditioned on. That is true no matter how expressive the model is. It also shows that in theory our model should learn meaningful latent structure.
4 Experimental evaluation
In this section we describe our experimental setup, and present results on CIFAR10.
4.1 Dataset and implementation
The CIFAR10 dataset  contains 6,000 images of 3232 pixels for each of the 10 object categories airplane, automobile, bird, cat, deer, dog, frog, horse, ship, truck. The images are split into 50,000 training images and 10,000 test images. We train all our models in a completely unsupervised manner, ignoring the class information.
We implemented our model based on existing architectures. In particular we use the VAE architecture of , and use logistic distributions over the RGB color values. We let the intermediate representation output by the VAE decoder be the per-pixel and per-channel mean values of the logistics, and learn per-channel scale parameters that are used across all pixels. The cumulative density function (CDF), given by the sigmoid function, is used to compute probabilities across the 256 discrete color levels, or fewer if a lower quantization level is chosen in . Using RGB values , we let denote the number of discrete color levels and define . The probabilities over the discrete color levels are computed from the logistic mean and variance and as
For the pixelCNN we use the architecture of , and modify it to be conditioned on the VAE decoder output , or possibly an upsampled version if has a lower resolution than . In particular, we apply standard non-masked convolutional layers to the VAE output, as many as there are pixelCNN layers. We allow each layer of the pixel-CNN to take additional input using non-masked convolutions from the feature stream based on the VAE output. This ensures that the conditional pixelCNN remains autoregressive.
To speed up training, we independently pretrain the VAE and pixelCNN in parallel, and then continue training the full model with both decoders. We use the Adamax optimizer  with a learning rate of without learning rate decay. We will release our TensorFlow-based code to replicate our experiments upon publication.
4.2 Quantitative performance evaluation.
Following previous work, we evaluate models on the test images using the bits-per-dimension (BPD) metric: the negative log-likelihood divided by the number of pixels values (33232). It can be interpreted as the average number of bits per RGB value in a lossless compression scheme derived from the model.
The comparison in Table 1 shows that our model performs on par with the state-of-the-art results of the pixelCNN++ model . Here we used the importance sampling-based bound of  with 150 samples to compute the BPD metric for our model.111The graphs in Figure 4 and Figure 8 are based on the bound in Eq. (7) to reduce the computational effort. We refer to Figure 2 for qualitative comparison of samples from our model and pixelCNN++, the latter generated using the publicly available code.
4.3 Effect of KL regularization strength.
In Figure 3 we show reconstructions of test images and samples generated by the VAE decoder, together with their corresponding conditional pixelCNN samples for different values of . As expected, the VAE reconstructions become less accurate for larger values of , mainly by lacking details while preserving the global shape of the input. At the same time, the samples become more appealing for larger , suppressing the unrealistic high-frequency detail in the VAE samples obtained at lower values of . Note that the VAE samples and reconstructions become more similar as increases, which makes the input to the pixelCNN during training and sampling more consistent.
For both reconstructions and samples, the pixelCNN clearly takes into account the output of the VAE decoder, demonstrating the effectiveness of our auxiliary loss to condition high-capacity pixelCNN decoders on latent variable representations. Samples from the pixelCNN faithfully reproduce the global structure of the VAE output, leading to more realistic samples, in particular for higher values of .
For the VAE reconstructions are near perfect during training, and the pixelCNN decoder does not significantly modify the appearance of the VAE output. For larger values of , the pixelCNN clearly adds significant detail to the VAE outputs.
Figure 4 traces the BPD metrics of both the VAE and pixelCNN decoder as a function of . We also show the decomposition in regularization and reconstruction terms. By increasing , the KL divergence can be pushed closer to zero. As the KL divergence term drops, the reconstruction term for the VAE rapidly increases and the VAE model obtains worse BPD values, stemming from the inability of the VAE to model pixel dependencies other than via the latent variables. The reconstruction term of the pixelCNN decoder also increases with , as the amount of information it receives drops. However, in terms of BPD which sums KL divergence and pixelCNN reconstruction, a substantial gain of 0.2 is observed increasing from 1 to 2, after which smaller but consistent gains are observed.
4.4 Role of the auxilliary representation
The auxilliary variables are taken into account:
3.3 shows that in theory it is always optimal for the autoregressive decoder to take the latent variables into account. Figure 5 demonstrates this empirically by displaying auxiliary representations with sampled from the prior as well as nine different samples from the autoregressive decoder conditioned on . This qualitatively shows that the low level detail added by the pixelCNN, which is crucial for log-likelihood performance, always respects the global structure of the image being conditioned on. The VAE decoder is trained with and weights very little in terms of KL divergence. Yet it controls the global structure of the samples, which shows that our setup can be used to get the best of both worlds. Figure 6 demonstrates that the latent variables of the encoder have learned meaningfull structure with latent variable interpolations. Samples are obtained by encoding ground truth images, then interpolating the latent variables obtained, decoding them with the decoder of the and adding low level detail with the pixelCNN.
|Conditional PixelCNN samples|
The auxilliary loss is necessary:
|PixCNN samples||PixCNN samples|
The fact that the autoregressive decoder ignores the latent variables could be attributed to optimization challenges, as explained in 3.3. In that case, the auxilliary loss could be used as an initialization scheme only, to guide the model towards a good use of the latent variables. To evaluate this we perform a control experiment where during training we first optimize our objective function in Eq. (7), i.e. including the auxiliary reconstruction term, and then switch to optimize the standard objective function of Eq. (6) without the auxiliary term. We proceed by training the full model to convergence then removing the auxiliary loss and fine-tuning from there. Figure 7 displays ground-truth images, with corresponding auxiliary reconstructions and conditional samples, as well as pure samples. The reconstructions have become meaningless and independent from the ground truth images. The samples display the same behavior: for each auxiliary representation four samples from the autoregressive component are displayed and they are independent from one another. Quantitatively, the KL cost immediately drops to zero when removing the auxiliary loss, in approximately two thousand steps of gradient descent. The approximate posterior immediately collapses to the prior and the pixel CNN samples become independent of the latent variables. This is the behavior predicted by the analysis of : the autoregressive decoder is sufficiently expressive that it suffers from using the latent variables.
4.5 Effect of different auxiliary images.
We assess the effect of using coarser RGB quantizations, lower spatial resolutions, and grayscale in the auxiliary image. All three make the VAE reconstruction task easier, and transfer the task of modeling color nuances and/or spatial detail to the pixelCNN.
The VAE reconstructions in Figure 8 (a) obtained using coarser color quantization carry less detail than reconstructions based on the original images using 256 color values, as expected. To understand the relatively small impact of the quantization level on the reconstruction, recall that the VAE decoder outputs the continuous means of the logistic distributions regardless of the quantization level. Only the reconstruction loss is impacted by the quantization level via the computation of the probabilities over the discrete color levels in Eq. (10). In Figure 8 (b) we observe small but consistent gains in the BPD metric as the number of color bins is reduced, showing that it is more effective to model color nuances using the pixelCNN, rather than the latent variables. We trained models with auxiliary images down-sampled to 1616 and 88 pixels, which yield 2.94 and 2.93 BPD, respectively. This is comparable to the 2.92 BPD obtained using our best model at scale 3232. We also trained models with 4-bit per pixel grayscale auxiliary images, as in . While the grayscale auxilliary images are subjectively the ones that have the best global structure, the results are still qualitatively inferior to those obtained by  with a pixelCNN modelling grayscale images. Our model does, however, achieve better quantitative performance at 2.93 BPD. In Figure 9 (a) we show samples obtained using models trained with 4-bit per pixel grayscale auxiliary images, in Figure 9 (b) with 32 color levels in the auxiliary image, and in Figure 9 (c) and (d) with auxiliary images of size 1616 and 88. The samples are qualitatively comparable, showing that in all cases the pixelCNN is able to compensate the less detailed outputs of the VAE decoder and that our framework can be used with a variety of intermediate reconstruction losses.
We presented a new approach to training generative image models that combine a latent variable structure with an autoregressive model component. Unlike prior approaches, it does not require careful architecture design to trade-off how much is modeled by latent variables and the autoregressive decoder. Instead, this trade-off can be controlled using a regularization parameter and choice of auxiliary target images. We obtain quantitative performance on par with the state of the art on CIFAR10, and samples from our model exhibit globally coherent structure as well as fine details.
This work has been partially supported by the grant ANR-16-CE23-0006 “Deep in France” and LabEx PERSYVAL-Lab (ANR-11-LABX-0025-01).
-  Arjovsky, M., Chintala, S., Bottou, L.: Wasserstein generative adversarial networks. In: ICML (2017)
-  Bachman, P.: An architecture for deep, hierarchical generative models. In: NIPS (2016)
-  Bengio, Y., Courville, A., Vincent, P.: Representation learning: A review and new perspectives. PAMI 35(8), 1798–1828 (2013)
-  Burda, Y., Salakhutdinov, R., Grosse, R.: Importance weighted autoencoders. In: ICLR (2016)
-  Chen, X., Kingma, D., Salimans, T., Duan, Y., Dhariwal, P., Schulman, J., Sutskever, I., Abbeel, P.: Variational lossy autoencoder. In: ICLR (2017)
-  Deshpande, A., Lu, J., Yeh, M.C., Chong, M., Forsyth, D.: Learning diverse image colorization. In: CVPR (2017)
-  Dinh, L., Krueger, D., Bengio, Y.: NICE: Non-linear independent components estimation. In: ICLR (2015)
-  Dinh, L., Sohl-Dickstein, J., Bengio, S.: Density estimation using real NVP. In: ICLR (2017)
-  Germain, M., Gregor, K., Murray, I., Larochelle, H.: MADE: Masked autoencoder for distribution estimation. In: ICML (2015)
-  Goodfellow, I., Pouget-Abadie, J., Mirza, M., Xu, B., Warde-Farley, D., Ozair, S., Courville, A., Bengio, Y.: Generative adversarial nets. In: NIPS (2014)
-  Gregor, K., Besse, F., Rezende, D., Danihelka, I., Wierstra, D.: Towards conceptual compression. In: NIPS (2016)
-  Gulrajani, I., Kumar, K., Ahmed, F., Taiga, A.A., Visin, F., Vazquez, D., Courville, A.: PixelVAE: A latent variable model for natural images. In: ICLR (2017)
-  Kingma, D., Ba, J.: Adam: A method for stochastic optimization. In: ICLR (2015)
-  Kingma, D., Rezende, D., Mohamed, S., Welling, M.: Semi-supervised learning with deep generative models. In: NIPS (2014)
-  Kingma, D., Salimans, T., Jozefowicz, R., Chen, X., Sutskever, I., Welling, M.: Improved variational inference with inverse autoregressive flow. In: NIPS (2016)
-  Kingma, D., Welling, M.: Auto-encoding variational Bayes. In: ICLR (2014)
-  Kolesnikov, A., Lampert, C.: PixelCNN models with auxiliary variables for natural image modeling. In: ICML (2017)
-  Krizhevsky, A.: Learning Multiple Layers of Features from Tiny Images. Master’s thesis, University of Toronto (2009)
-  Larochelle, H., Murray, I.: The neural autoregressive distribution estimator (2011)
-  van den Oord, A., Kalchbrenner, N., Vinyals, O., Espeholt, L., Graves, A., Kavukcuoglu, K.: Conditional image generation with PixelCNN decoders. In: NIPS (2016)
-  Oord, A.v.d., Kalchbrenner, N., Kavukcuoglu, K.: Pixel recurrent neural networks. In: ICML (2016)
-  Rasmus, A., Berglund, M., Honkala, M., Valpola, H., Raiko, T.: Semi-supervised learning with ladder networks. In: NIPS (2015)
-  Reed, S., van den Oord, A., Kalchbrenner, N., Colmenarejo, S.G., Wang, Z., Belov, D., de Freitas, N.: Parallel multiscale autoregressive density estimation. In: ICML (2017)
-  Rezende, D., Mohamed, S., Wierstra, D.: Stochastic backpropagation and approximate inference in deep generative models. In: ICML (2014)
-  Salimans, T., Karpathy, A., Chen, X., Kingma, D.: Pixelcnn++: Improving the pixelcnn with discretized logistic mixture likelihood and other modifications. In: ICLR (2017)
-  Yan, X., Yang, J., Sohn, K., Lee, H.: Attribute2image: Conditional image generation from visual attributes. In: ECCV (2016)