# Variational image compression with a scale hyperprior

Hyperpriors let learned image codecs model dependencies among latent scales

Johannes Ballé, David Minnen, Saurabh Singh, Sung Jin Hwang, Nick Johnston · arXiv · 2018-2-1

- **Problem** Learned image codecs usually use a fully factorized entropy model. It cannot capture dependencies among neighboring latent scales, so the latents are coded with wasted bits.
- **Method** The authors add a hyperprior: a side-information branch that predicts each latent's scale from a quantized hyper-latent. The model trains end-to-end with uniform noise in place of quantization.
- **Results** With MS-SSIM training, the hyperprior model consistently surpasses Rippel and Bourdev (2017) on Kodak. With squared-error training, it outperforms other ANN-based methods in PSNR.

## Why a factorized entropy model wastes bits

Learned image codecs quantize a latent representation and code the quantized values losslessly with an entropy model. The length of the bitstream is governed by how closely that model matches the marginal distribution of the latents. The expected code length equals a cross entropy between that marginal and the entropy model, so any mismatch between the two is paid for in bits.

In the ANN-based codecs considered here, the entropy model is usually a joint or a fully factorized distribution. A fully factorized model cannot represent statistical dependencies among the latents, so those latents are coded suboptimally. Classical codecs reduce this mismatch by sending side information. HEVC, for example, signals its variable block partition to the decoder before the blocks are decoded.

A visualization of the latents of a factorized-prior model shows nonzero responses clustered around edges and textured regions. The scales of neighboring latents therefore vary together, a dependency that the factorized prior cannot express.

## How rate and distortion enter the training objective

The model follows transform coding: an analysis transform \\(g\_a\\) maps the image to the latents \\(y\\), these are quantized to \\(\\hat{y}\\), and a synthesis transform \\(g\_s\\) reconstructs the image from \\(\\hat{y}\\). Rate is the expected code length under the entropy model, and distortion is the expected difference between the reconstruction and the original image.

A weight \\(\\lambda\\) on the distortion term selects a point on the rate–distortion trade-off.

Quantization has a gradient that is zero almost everywhere, so the transform parameters cannot be trained by plain gradient descent. The authors replace quantization with additive uniform noise during training, giving the noisy latents \\(\\tilde{y}\\), and switch back to real quantization when the model is used for compression.

Under this approximation, the inference distribution is a uniform density of unit width centered on each analysis output. Because that width is fixed, the first term of the KL divergence is constant and drops out, leaving a weighted distortion term and a rate term.

The rate term then becomes a differential cross entropy between the marginal of the noisy latents and the prior. The authors treat this as a close approximation to the discrete entropy.

## Adding a hyperprior over the latent scales

The factorized prior ignores the coupling of scales across space. The authors add latent variables \\(\\tilde{z}\\) that capture this coupling, so that the latents can be treated as independent once \\(\\tilde{z}\\) is given.

Each \\(\\tilde{y}\_i\\) is modeled as a zero-mean Gaussian whose standard deviation is \\(\\tilde{\\sigma} = h\_s(\\tilde{z};\\theta\_h)\\). Each Gaussian is convolved with a standard uniform density. On the inference side, a second analysis transform \\(h\_a\\) is stacked on \\(y\\) to give \\(z = h\_a(y;\\phi\_h)\\). The joint variational posterior then factorizes into uniform densities over both \\(y\\) and \\(z\\).

The hyperlatents use the same non-parametric, fully factorized density model as the latents. The loss then contains the distortion term and two cross entropies, one for \\(\\tilde{y}\\) under the scale-dependent prior and one for \\(\\tilde{z}\\), which the authors read as side information.

Each univariate density is convolved with a standard uniform density. The authors state that this lets the prior match the marginal more closely, since the posterior has unit-width uniform densities.

At test time the encoder quantizes \\(z\\) to \\(\\hat{z}\\), codes it, and uses \\(\\hat{z}\\) to estimate \\(\\hat{\\sigma}\\) for coding \\(\\hat{y}\\). The decoder therefore decodes \\(\\hat{z}\\) first, rebuilds the same scales, and only then decodes \\(\\hat{y}\\).

## Networks and the arithmetic coder

The transforms \\(g\_a\\) and \\(g\_s\\) are convolutions interleaved with GDN and IGDN, which implement local divisive normalization. The hyper-transforms \\(h\_a\\) and \\(h\_s\\) use convolutions with rectified linear units. The factorized-prior and hyperprior models share the same \\(g\_a\\) and \\(g\_s\\), so that they can be compared directly.

Filter counts depend on \\(\\lambda\\). Five of the lower \\(\\lambda\\) values use \\(N = 128\\) and \\(M = 192\\), and the three higher values use \\(N = 192\\) and \\(M = 320\\).

Arithmetic coding uses a simple non-adaptive binary coder. Each element is written as a binary integer and coded from its most significant bit down to its least significant bit. Because the decoder knows \\(\\hat{\\sigma}\\) before it decodes \\(\\hat{y}\\), each element's probability mass function is computed on the fly from a Gaussian with scale \\(\\hat{\\sigma}\_i\\) convolved with the uniform density.

This integral has a closed form, and the coder needs no separate training.

## Training corpus and optimization

Training used approximately 1 million color JPEG images scraped from the web, with heights and widths between 3000 and 5000 pixels. Images with excessive saturation were removed to reduce the share of non-photographic content.

Each image was downsampled by a random factor so that the minimum of its height and width fell between 640 and 1200 pixels, which reduces existing compression artifacts. Then randomly placed 256×256 crops were extracted. Minibatches of 8 crops were used with the Adam optimizer at a learning rate of 10−4. The authors report that batch normalization and learning rate decay gave no benefit.

In total 32 separate models were trained: half with a hyperprior and half without, half with mean squared error and half with MS-SSIM as the distortion loss. Each of these combinations was trained at 8 values of \\(\\lambda\\).

## PSNR results on Kodak

All models are evaluated on the Kodak dataset. The PSNR curves plot distortion against bits per pixel, and each point aggregates results over equal values of \\(\\lambda\\).

Models optimized for MS-SSIM score poorly in PSNR. The factorized-prior model optimized for squared error outperforms JPEG and the ANN-based methods of Theis et al. (2017) and Ballé et al. (2017).

The factorized-prior model does not beat BPG, the still-image encapsulation of HEVC. The squared-error hyperprior model comes close to BPG, does better at higher rates than at lower rates, and substantially exceeds all published ANN-based methods. Other published ANN-based methods that are not plotted either underperform the plotted ones or did not make their data available to the authors.

In the PSNR comparison, the squared-error hyperprior model outperforms all other ANN-based methods and approximates HEVC performance. The authors conclude that the training loss has to match the evaluation metric to get good results.

## MS-SSIM results on Kodak

Because MS-SSIM lies between 0 and 1, the curves convert it to decibels with \\(-10\\log\_{10}(1-d)\\), where \\(d\\) is the MS-SSIM value. Most compared methods score well above 0.9 before conversion.

The factorized-prior model matches Rippel and Bourdev (2017), with better results at high bit rates and slightly worse results at low bit rates. The authors note that this holds even though that model has a multiscale architecture, a GAN loss and a context-adaptive entropy model. The hyperprior model trained on MS-SSIM adds gains across the rate–distortion trade-offs, and the authors describe it as consistently surpassing the state of the art on this metric.

Across rates, the hyperprior models consistently outperform the corresponding factorized-prior models. The authors read this as evidence that reducing the mismatch between prior and marginal is important.

## Cost of side information

The side information rate was measured for the squared-error hyperprior model, averaged over the Kodak set and normalized per pixel.

The split of bits between \\(\\hat{z}\\) and \\(\\hat{y}\\) is not fixed by the architecture. It follows from optimizing the loss in the objective.

## How the training loss changes reconstructions

At low rates the artifacts depend on the training loss. The MS-SSIM-trained hyperprior model reaches 0.1864 bpp with PSNR 27.99 and MS-SSIM 0.9803, while the squared-error model reaches 0.1932 bpp with PSNR 32.26 and MS-SSIM 0.9713.

In the airplane example, the MS-SSIM model adds detail to the low-contrast grass and removes detail from the high-contrast text on the side of the airplane. The authors judge that the squared-error models give subjectively better results when semantically relevant high-contrast areas matter.

The authors stress that neither distortion metric captures image semantics, which is why the choice of loss is hard. Comparing hyperprior and factorized-prior reconstructions visually, the authors find no change in the nature of the artifacts. The hyperprior mainly yields more detail at a lower bit rate.

## Relation to other learned codecs

Santurkar et al. (2017) combine a VAE with a GAN, first training a decoder with an adversarial loss and then fitting an encoder to minimize reconstruction error. Rippel and Bourdev (2017) pair an adversarial loss with a weighted MS-SSIM term.

Theis et al. (2017) replace the gradient of the quantizer with the identity and derive a differentiable upper bound on the discrete rate. Ballé et al. (2016b) replace quantization with additive uniform noise and the discrete rate with a differential entropy. The authors note that the second approach makes the discrete prior evaluable as a function of the hyperlatents, which makes a hyperprior practical.

Wainwright and Simoncelli (2000) model linear filter responses as conditionally Gaussian with shared scale multipliers, and Lyu and Simoncelli (2009) extend this to a global image model. The present model can be read as an extension in which the responses come from a learned nonlinear transform and an approximate inference model is added.

Toderici et al. (2017) use a binarized latent representation with no trainable entropy model. Johnston et al. (2017) add an adaptive entropy model that is kept out of the rate term during training, which the authors argue breaks end-to-end optimization.

The authors note that GDN removes statistical dependencies more efficiently than pointwise nonlinearities. Dependencies still remain in the latents of their models, which they attribute to the rate–distortion trade-off rather than to the transforms.

## Limitations

MS-SSIM training can produce results that conflict with human expectations, and the authors say this happens more often than they expected. Their evidence for this is the single airplane example.

The authors state that unless human rating experiments are conducted, methods should be compared on more than one type of metric.

The quantitative evaluation in the main text uses only the Kodak dataset.

Significant dependencies remain among the latents even with the hyperprior, and the authors leave open whether rate–distortion optimality implies full independence at arbitrary values of \\(\\lambda\\).

## Paper info

- **Authors**: Johannes Ballé, David Minnen, Saurabh Singh, Sung Jin Hwang, Nick Johnston
- **Venue**: arXiv · Preprint
- **First published**: 2018-2-1
- **Added**: 2026-11-12
- **Updated**: 2018-5-1
- **Version**: v2
- **arXiv**: 1802.01436
- **Category**: eess.IV · cs.IT
- **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/1802.01436v2) · [PDF ↗](https://arxiv.org/pdf/1802.01436v2)

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

Johannes Ballé, David Minnen, Saurabh Singh, Sung Jin Hwang, Nick Johnston (2018). Variational image compression with a scale hyperprior. arXiv:1802.01436v2. https://arxiv.org/abs/1802.01436v2

**BibTeX**

```
@misc{ball2018variational,
  title = {{Variational image compression with a scale hyperprior}},
  author = {Johannes Ballé and David Minnen and Saurabh Singh and Sung Jin Hwang and Nick Johnston},
  year = {2018},
  eprint = {1802.01436},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1802.01436v2}
}
```

## Related papers

- [Tutorial on Variational Autoencoders](https://refivu.com/en/papers/51a9cfc2-6285-4935-b55a-3d6450af8eff-tutorial-on-variational-autoencoders.md)
- [EDiffSR: An Efficient Diffusion Probabilistic Model for Remote Sensing Image Super-Resolution](https://refivu.com/en/papers/76f50706-1489-43e9-9b29-6e7734ea5128-ediffsr-an-efficient-diffusion-probabilistic-model-for.md)
- [MERF: Memory-Efficient Radiance Fields for Real-time View Synthesis in Unbounded Scenes](https://refivu.com/en/papers/b88df5f3-e59a-4fcd-9cfd-d031cf876738-merf-memory-efficient-radiance-fields-for-real-time.md)
- [MagicAnimate: Temporally Consistent Human Image Animation using Diffusion Model](https://refivu.com/en/papers/d7e4c79d-ac46-4e0f-aef6-34e570d43e2f-magicanimate-temporally-consistent-human-image-animation.md)

## Other paper commentary

- [DeblurGAN: Blind Motion Deblurring Using Conditional Adversarial Networks](https://refivu.com/en/papers/bcd086aa-43d4-404f-aae8-d730dc8d20db-deblurgan-blind-motion-deblurring-using-conditional.md)
- [Ups and Downs: Modeling the Visual Evolution of Fashion Trends with One-Class Collaborative Filtering](https://refivu.com/en/papers/c7f79e17-0229-4098-a2b0-1f184335cf4d-ups-and-downs-modeling-the-visual-evolution-of.md)
- [ProxylessNAS: Direct Neural Architecture Search on Target Task and Hardware](https://refivu.com/en/papers/40299bf6-79d4-4e50-829c-39acb400238f-proxylessnas-direct-neural-architecture-search-on-target.md)
- [Beyond Correlation Filters: Learning Continuous Convolution Operators for Visual Tracking](https://refivu.com/en/papers/cc3e5d8d-4cc2-494c-bc24-c9b0fd010736-beyond-correlation-filters-learning-continuous-convolution.md)
- [3D Semantic Segmentation with Submanifold Sparse Convolutional Networks](https://refivu.com/en/papers/03d04653-f014-489b-8502-00fe22ca0646-3d-semantic-segmentation-with-submanifold-sparse.md)
- [Sigmoid Loss for Language Image Pre-Training](https://refivu.com/en/papers/c9aaadc4-ef69-4682-a730-51fb42cbb35f-sigmoid-loss-for-language-image-pre-training.md)
- [HunyuanVideo: A Systematic Framework For Large Video Generative Models](https://refivu.com/en/papers/bf878ce4-776a-4af5-9994-66e35572b481-hunyuanvideo-a-systematic-framework-for-large-video.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)
- [Robust and Communication-Efficient Federated Learning from Non-IID Data](https://refivu.com/en/papers/8cfbbb74-26ed-46b1-9bcb-908c177043d6-robust-and-communication-efficient-federated-learning-from.md)
- [Machine Learning for Combinatorial Optimization: a Methodological Tour d'Horizon](https://refivu.com/en/papers/9cbd91bd-7b47-473f-9fbe-9e1a438567b0-machine-learning-for-combinatorial-optimization-a.md)
- [Deep Learning on Graphs: A Survey](https://refivu.com/en/papers/2184aed4-7bc8-45a4-81a9-0ad60f8dc1c1-deep-learning-on-graphs-a-survey.md)
- [Metrics for Multi-Class Classification: an Overview](https://refivu.com/en/papers/78ca6b47-f74d-4a51-a805-f5f83bb18a77-metrics-for-multi-class-classification-an-overview.md)

## Terms in this paper

- [PSNR](https://refivu.com/en/terms/fcbb9b8276a7-psnr)
- [mean squared error](https://refivu.com/en/terms/e8df98e6d7b7-mean-squared-error)
- [Variational Autoencoder](https://refivu.com/en/terms/03e579ac2e7c-variational-autoencoder)

---

AI-written text can contain mistakes. [Refivu](https://refivu.com/en/papers/862ebff4-6ece-4ccf-a0cf-aa1b89192db4-variational-image-compression-with-a-scale-hyperprior)
