# Pixel Recurrent Neural Networks

Pixel recurrent networks predict each pixel of natural images in sequence

Aaron van den Oord, Nal Kalchbrenner, Koray Kavukcuoglu · arXiv · 2016-1-25

- **Problem** Modeling natural images needs a density that is expressive, tractable and scalable at once. Earlier latent variable models need an inference step that can be intractable and can limit performance.
- **Method** PixelRNN predicts each color value of each pixel as one of 256 discrete values with a softmax. Each pixel is conditioned on earlier pixels through Row LSTM or Diagonal BiLSTM layers, instead of assuming a continuous density.
- **Results** The Diagonal BiLSTM reaches 3.00 bits/dim on CIFAR-10 test without data augmentation. The Row LSTM reaches 3.07 on the same test, and the PixelCNN 3.14.

## Why natural-image likelihoods are hard

Natural images are high dimensional and strongly structured, which makes their distribution hard to estimate. A model therefore has to be expressive enough to capture that structure while staying tractable and scalable to train.

Much earlier work relied on stochastic latent variable models such as VAEs, which aim at useful representations but need an inference step that can be intractable and can limit performance. Autoregressive models avoid such an inference step by writing the joint distribution as a product of conditionals, which turns image modeling into a sequence problem.

A sequence model in that setting has to capture highly nonlinear, long-range correlations between pixels, and recurrent networks offer a compact parameter sharing across the conditional distributions. Two-dimensional recurrent networks had already shown promise on grayscale images and textures, and this work pushes that line toward large-scale natural images.

## Pixel-by-pixel factorization over discrete values

An n by n image is read row by row into a sequence of n squared pixels, and its probability is written as a product of conditionals, each given all earlier pixels. The joint is the product below, where each factor is the probability of pixel \\(x\_i\\) given the pixels before it. \\\[ p(x) = \\prod\_{i=1}^{n^2} p(x\_i \\mid x\_1,\\dots,x\_{i-1}) \\\]

Within each pixel the three color channels are factored in turn, so the green value is conditioned on the red value and the blue value on both. \\\[ p(x\_i,R \\mid x\_{\<i})\\, p(x\_i,G \\mid x\_{\<i}, x\_{i,R})\\, p(x\_i,B \\mid x\_{\<i}, x\_{i,R}, x\_{i,G}) \\\] Each color is therefore conditioned on the other channels already produced as well as on all earlier pixels.

Each channel value is treated as one of 256 discrete categories, and each conditional is a multinomial produced by a softmax layer. Because no density family is assumed, the output can place mass on several modes or on skewed shapes, which is the property that favors it over the continuous densities used in earlier work. Training and evaluation compute these distributions for all positions in parallel, whereas generating an image has to proceed one pixel at a time.

## Row LSTM and Diagonal BiLSTM layers

The Row LSTM is unidirectional and runs from top to bottom, computing the states of a whole row at once with a one-dimensional convolution. Its input-to-state part is a masked convolution with a k by 1 kernel over the full input map, so it can be computed for all positions in advance, while the state-to-state part is applied one row at a time.

With \\(h\_{i-1}\\) and \\(c\_{i-1}\\) the previous hidden and cell states and \\(x\_i\\) row \\(i\\) of the input map, one step is: \\\[ \[o\_i, f\_i, i\_i, g\_i\] = \\sigma(K\_{ss} \\circledast h\_{i-1} + K\_{is} \\circledast x\_i),\\quad c\_i = f\_i \\odot c\_{i-1} + i\_i \\odot g\_i,\\quad h\_i = o\_i \\odot \\tanh(c\_i) \\\] The logistic sigmoid is applied to the output, forget and input gates, and tanh to the content gate.

Because the Row LSTM's receptive field is triangular, it cannot reach the full available context.

The Diagonal BiLSTM aims to parallelize along diagonals while reaching the whole preceding context at any image size. Each of its two directions starts at one corner and sweeps toward the opposite corner, computing one diagonal per step. To make diagonals line up in memory, each row is offset by one position relative to the row above, which gives an n by (2n minus 1) map that is cut back to n by n afterwards.

Its input-to-state part is a 1 by 1 convolution, and its state-to-state part is a column-wise convolution with a 2 by 1 kernel. The output of the backward direction is moved down one row and summed with the forward output, which keeps future pixels out of the prediction. A 2 by 1 kernel keeps each step's computation small and nonlinear, and larger kernels add little because the receptive field is already global.

## Residual connections, masks and the PixelCNN

Residual connections link each LSTM layer to the next, which speeds convergence and lets signals move more directly through a deep stack of up to twelve layers. The layer input has 2h features; the input-to-state part reduces them to h features per gate, a 1 by 1 convolution lifts the recurrent output back to 2h features, and the layer input is added to it.

This adds no extra gates, which distinguishes it from earlier gated approaches to depth.

The feature maps are split into three groups for the RGB channels: red sees only pixels above and to the left, green also sees red, and blue sees both red and green. Mask A is applied only to the first convolutional layer and does not allow a color to connect to itself, while mask B is applied to all later input-to-state transitions and does allow that self-connection.

The masks are implemented by zeroing the corresponding weights after each update.

The PixelCNN replaces the recurrence with standard masked convolutions, which give a bounded receptive field and compute all positions at once. Pooling is not used, so spatial resolution is kept, and the network has fifteen layers, beginning with a 7 by 7 convolution with mask A and using 3 by 3 convolutions with mask B.

## Conditioning on a small image

An unconditional PixelRNN first generates a small s by s image that is subsampled from the original. A conditional PixelRNN then generates the larger n by n image, and each of its layers is biased by an upsampled version of the small image. Deconvolutional layers upsample the small image to a c by n by n map, and a 1 by 1 unmasked convolution maps that map to 4h by n by n and adds it to each layer's input-to-state map.

## Model sizes and training choices

On MNIST the Diagonal BiLSTM has 7 layers with h = 16, and its output layers have 32 feature maps. On CIFAR-10 the Row and Diagonal BiLSTMs have 12 layers with h = 128, the PixelCNN has 15 layers with h = 128, and the output layers have 1024 feature maps. For 32 by 32 ImageNet a 12-layer Row LSTM with h = 384 is used, and for 64 by 64 ImageNet a 4-layer Row LSTM with h = 512 is used, without residual connections.

RMSProp gave the best convergence among the update rules tried and was used for all experiments, with learning rate schedules set by hand for each dataset. Batches had 16 images for MNIST and CIFAR-10, and 64 and 32 images for 32 by 32 and 64 by 64 ImageNet respectively. Images were only scaled and centered, and the initial recurrent state is learned.

MNIST scores are negative log-likelihoods in nats, and CIFAR-10 and ImageNet scores are in bits per dimension. The total discrete log-likelihood is normalized by the number of dimensions, which is 3072 for a 32 by 32 by 3 CIFAR-10 image.

## Residual, skip and depth ablations

In a 12-layer Row LSTM on CIFAR-10 validation, residual connections without skip connections lower the value from 3.22 to 3.07 bits/dim. Skip connections alone give 3.09 without residual connections, and using both residual and skip connections gives 3.06. The authors report that residual connections are about as effective as skip connections, and that using both keeps that benefit.

With residual and skip connections, validation error falls as layers are added: 3.30 bits/dim at one layer, 3.20 at two, 3.17 at three, 3.09 at six, 3.08 at nine and 3.06 at twelve. The improvement with depth holds up to the 12 layers tested.

For the Row LSTM on CIFAR-10 validation, the softmax output gives 3.06 bits/dim. The same model with a mixture of conditional Gaussian scale mixtures gives 3.22 bits/dim, so the discrete softmax is the lower value here.

## Benchmark results on MNIST, CIFAR-10 and ImageNet

On binarized MNIST the Diagonal BiLSTM with 7 layers and h = 16 reaches 79.20 nats on the test set, below the 80.54 of the Row LSTM and the 81.30 of the PixelCNN in the same table. A single-layer Diagonal BiLSTM with h = 32 reaches 80.75. The authors state that this is the best MNIST result they know of so far.

On CIFAR-10 test without data augmentation, the Diagonal BiLSTM reaches 3.00 bits/dim, the Row LSTM 3.07 and the PixelCNN 3.14. Their training values are 2.93, 3.00 and 3.08 bits/dim. The best prior entry in that table is RIDE at 3.47 bits/dim, which the table gives as a personal communication, and the uniform distribution is at 8.00. They attribute the ordering to receptive field size: the Diagonal BiLSTM sees the whole preceding context, the Row LSTM a partly occluded one, and the PixelCNN the fewest pixels.

To the authors' knowledge there are no published results on ImageNet to compare against, so the table reports only the models' own numbers. The 32 by 32 model reaches 3.86 bits/dim on validation (3.83 on training), and the 64 by 64 model reaches 3.63 bits/dim (3.57 on training). They report no overfitting, since validation performance improved with model size and depth.

Samples from the 32 by 32 ImageNet model capture more global structure than those from the CIFAR-10 model, which the authors link to its larger size and more training data.

On 64 by 64 ImageNet the multi-scale model reaches log-likelihood similar to the single-scale model, but its samples look globally more coherent on visual inspection.

## Limits of sampling, scale and scope

Generation is sequential, because each sampled pixel has to be fed back into the network before the next one can be predicted, even though training and evaluation run in parallel.

The authors report that the size of the ImageNet models is currently limited by computation time and GPU memory. ImageNet images are less compressible than CIFAR-10 images, and the CIFAR-10 images were likely resized with a different algorithm, which can change compression performance.

Depth was tested only up to 12 LSTM layers, and the 64 by 64 ImageNet model uses 4 layers without residual connections. The CIFAR-10 results are without data augmentation, and the MNIST results are on the binary version of the dataset. The multi-scale benefit is judged from samples, since its log-likelihood is similar to that of the single-scale model.

## Paper info

- **Authors**: Aaron van den Oord, Nal Kalchbrenner, Koray Kavukcuoglu
- **Venue**: arXiv · Preprint
- **First published**: 2016-1-25
- **Added**: 2026-11-13
- **Updated**: 2016-8-19
- **Version**: v3
- **arXiv**: 1601.06759
- **Category**: cs.CV · cs.LG · cs.NE
- **Original paper terms**: [arXiv non-exclusive 1.0](https://arxiv.org/licenses/nonexclusive-distrib/1.0/)
- **What we show**: Paper info and commentary

[Original paper ↗](https://arxiv.org/abs/1601.06759v3) · [PDF ↗](https://arxiv.org/pdf/1601.06759v3)

AI commentary is a separate explanation from the original paper and may contain errors. The original paper and figures follow each source's terms of use and any rights noted separately.

## Quote from the paper

Aaron van den Oord, Nal Kalchbrenner, Koray Kavukcuoglu (2016). Pixel Recurrent Neural Networks. arXiv:1601.06759v3. https://arxiv.org/abs/1601.06759v3

**BibTeX**

```
@misc{oord2016pixel,
  title = {{Pixel Recurrent Neural Networks}},
  author = {Aaron van den Oord and Nal Kalchbrenner and Koray Kavukcuoglu},
  year = {2016},
  eprint = {1601.06759},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1601.06759v3}
}
```

## Other paper commentary

- [Fourier Features Let Networks Learn High Frequency Functions in Low Dimensional Domains](https://refivu.com/en/papers/0db80d86-03b8-4275-8e19-39d4c7f0fd3d-fourier-features-let-networks-learn-high-frequency-functions.md)
- [CSRNet: Dilated Convolutional Neural Networks for Understanding the Highly Congested Scenes](https://refivu.com/en/papers/991e4e38-4c34-4634-839b-1c56b435a442-csrnet-dilated-convolutional-neural-networks-for.md)
- [Sequence Transduction with Recurrent Neural Networks](https://refivu.com/en/papers/882824aa-8ddf-4d40-8608-c68a08ecc168-sequence-transduction-with-recurrent-neural-networks.md)
- [Super-Convergence: Very Fast Training of Neural Networks Using Large Learning Rates](https://refivu.com/en/papers/6770e9ca-a3e2-40e5-bf7e-fd1daf28cf68-super-convergence-very-fast-training-of-neural-networks.md)
- [Cascaded Pyramid Network for Multi-Person Pose Estimation](https://refivu.com/en/papers/917d4471-88d7-4f2f-b082-558d51356b78-cascaded-pyramid-network-for-multi-person-pose-estimation.md)
- [Photonics for artificial intelligence and neuromorphic computing](https://refivu.com/en/papers/20f5aec1-bc52-4917-93d6-725c8afc0672-photonics-for-artificial-intelligence-and-neuromorphic.md)
- [MetaGPT: Meta Programming for A Multi-Agent Collaborative Framework](https://refivu.com/en/papers/91dd7973-493a-4820-91e2-46a50eb0a70e-metagpt-meta-programming-for-a-multi-agent-collaborative.md)
- [GQA: A New Dataset for Real-World Visual Reasoning and Compositional Question Answering](https://refivu.com/en/papers/d0afea32-dc3f-4529-bea4-dbdd41e95856-gqa-a-new-dataset-for-real-world-visual.md)
- [Moment Matching for Multi-Source Domain Adaptation](https://refivu.com/en/papers/8dd0a99c-d46a-4b5e-bfd0-6d72f38da2fc-moment-matching-for-multi-source-domain-adaptation.md)
- [Semi-Supervised Learning with Deep Generative Models](https://refivu.com/en/papers/e4821cb7-e7f9-4874-ba36-d94522c55bbb-semi-supervised-learning-with-deep-generative-models.md)
- [The Google Similarity Distance](https://refivu.com/en/papers/bb278d2d-7ba0-4fc6-9c9b-7e248f6965c2-the-google-similarity-distance.md)
- [HOGWILD!: A Lock-Free Approach to Parallelizing Stochastic Gradient Descent](https://refivu.com/en/papers/4f25abad-2562-433a-bc64-107b6d812ffb-hogwild-a-lock-free-approach-to-parallelizing-stochastic.md)

## Terms in this paper

- [ImageNet](https://refivu.com/en/terms/5eadad128667-imagenet)
- [CIFAR-10](https://refivu.com/en/terms/19035a518d0a-cifar-10)
- [MNIST](https://refivu.com/en/terms/28b9bb66d1c6-mnist)
- [RMSProp](https://refivu.com/en/terms/a1984fdf7b1d-rmsprop)
- [long short-term memory](https://refivu.com/en/terms/1eac61fff4b1-long-short-term-memory)
- [negative log-likelihood](https://refivu.com/en/terms/e6d7135ed9ca-negative-log-likelihood)
- [residual connections](https://refivu.com/en/terms/bd7b8af195ce-residual-connections)
- [Autoregressive models](https://refivu.com/en/terms/66bedb44b32b-autoregressive-models)
- [PixelCNN](https://refivu.com/en/terms/4ec4f3973797-pixelcnn)
- [bits/dim](https://refivu.com/en/terms/ba9b1deef901-bits-dim)
- [PixelRNN](https://refivu.com/en/terms/cd7eb9e1f966-pixelrnn)

---

AI-written text can contain mistakes. [Refivu](https://refivu.com/en/papers/d5d56398-b505-4053-bf0e-8b169a060e49-pixel-recurrent-neural-networks)
