TL;DR
Glow is a generative model for images that learns an exact probability for each image, and that can also generate new images by running the model backwards. It is a flow: a stack of invertible steps that turn an image into simple Gaussian noise and back. Its two new ingredients are actnorm, a per-channel scale and shift set from the data, and a learned invertible 1x1 convolution in place of a fixed reversal of channels. The paper shows this improves log-likelihood on standard benchmarks and yields realistic 256 by 256 face images.
Builds on: Normalizing Flow, Affine Coupling Layer, Pointwise (1x1) Convolution, Change of Variables Formula, Maximum Likelihood Estimation · Leads to: later flow models for images that use learned channel mixing in place of fixed permutations
Why it mattered
The paper's authors argue that likelihood-based image models were held back by a trade-off. Autoregressive models give exact likelihoods but generate one value at a time, which is slow for large images. Variational autoencoders train in parallel but optimise only a lower bound on the likelihood. Generative adversarial networks give sharp samples but have no encoder and no likelihood. Flow models offer exact likelihoods, exact inference and parallel synthesis, but the paper says they had "gained little attention in the research community". Glow is the authors' attempt to show that a flow can match the quality of other approaches on large images, which the paper claims is the first likelihood-based model to synthesise high-resolution natural images efficiently, to the authors' knowledge.
The problem
A generative model must assign a probability to every image, and the usual way to train it is to maximise the log-likelihood of the training data. For a flow, the difficulty is computing that log-likelihood. A flow maps an image x to a latent z through invertible steps, and the density of x is the density of z times a correction for how the steps stretch space. Computing that correction, the log-determinant of a Jacobian, is cheap only when the steps are chosen with care. Earlier flows (NICE and RealNVP) used a fixed reversal of the channel order between coupling layers to let every channel affect every other one. The paper's question is whether a learned mixing step can do this better, and still keep the log-determinant cheap.
How it works
A Glow model is a stack of steps, grouped into levels. Each step has three parts, shown in the paper's Figure 2: actnorm, then an invertible 1x1 convolution, then an affine coupling layer. Here is one step traced on a tiny image.
- Start with a tensor. Take a 2 by 2 image with 3 channels, so there are 4 spatial positions and each has 3 numbers. Call it h.
- Actnorm. Scale and shift each channel by a learned value. The values are set on the first minibatch so each channel starts with zero mean and unit variance. This replaces batch normalization, which the paper says degrades with small per-device minibatches. The log-determinant of this step is simple: the sum of the log scales times the number of positions.
- Invertible 1x1 convolution. At each position, multiply the 3 channel values by a learned 3 by 3 matrix W. The same W is used at every position. This mixes the channels. If W is invertible, the step can be reversed by multiplying with the inverse of W.
- Its log-determinant. Because the same matrix acts at each of the 4 positions, the log-determinant is 4 times log of the absolute determinant of W. If det(W) = 2, the value is 4 × log 2 ≈ 2.77.
- Affine coupling. Split the channels into two halves. Use one half to compute a scale and a shift with a small neural network, and apply them to the other half. The half used as input is copied unchanged, so the step can be inverted: knowing the output halves, you recompute the scale and shift from the unchanged half and undo the transform.
- Stack and check. Repeat the three parts K times per level, and arrange the levels in the multi-scale architecture that the paper takes from RealNVP. Check that every step has an inverse, which is what makes exact inference and sampling possible.
flowchart LR
X["image x"] --> A["actnorm: per-channel scale and shift"]
A --> C["invertible 1x1 convolution W"]
C --> F["affine coupling layer"]
F --> R["repeat K times per level"]
R --> Z["latent z: Gaussian noise"]
The math
Each step in the walkthrough has a formula. Symbols follow the paper: x is the data, h are intermediate tensors, z is the latent, and c is the number of channels.
Step 2 in symbols: actnorm
Actnorm applies at each spatial position , where is element-wise multiplication, is a per-channel scale and a per-channel shift. Its log-determinant is for an image of height and width .
Step 3 in symbols: the invertible 1x1 convolution
The layer applies with a matrix. Its inverse is . The log-determinant is
Computing or differentiating costs , while the convolution itself costs . The paper initialises W as a random rotation, whose determinant has absolute value 1 and log-determinant 0.
To make the determinant cheap for large , the paper parameterises W through its LU decomposition:
where P is a fixed permutation matrix, L is lower triangular with ones on the diagonal, U is upper triangular with zeros on the diagonal, and s is a vector. The log-determinant then reduces to , which costs . The paper notes that for its networks it did not measure a large difference in wall-clock time.
Step 5 in symbols: the affine coupling layer
Split into halves . A neural network computes . Then
The inverse recomputes from , which equals , and then sets . The log-determinant is , because the Jacobian is triangular.
The full log-likelihood
Stacking the steps with and , the change of variables gives
with in the standard setup. Training minimises the average negative log-likelihood over the data. For images, the paper reports results in bits per dimension, the standard conversion: the negative log-likelihood divided by the number of dimensions and by log 2, which turns nats into bits.
Results
The paper's first experiment is an ablation on CIFAR-10. It compares three ways to permute channels, RealNVP's reversal, a fixed random permutation, and the learned 1x1 convolution, with additive and affine coupling. The 1x1 convolution gives lower negative log-likelihood and converges faster in both cases, and the affine models converge faster than the additive ones. The authors report a 0.2% increase in parameters and about a 7% increase in wall-clock time.
The main comparison is with RealNVP, in bits per dimension (lower is better) from Table 2:
- CIFAR-10: RealNVP 3.49, Glow 3.35.
- ImageNet 32 by 32: RealNVP 4.28, Glow 4.09.
- ImageNet 64 by 64: RealNVP 3.98, Glow 3.81.
- LSUN bedroom: RealNVP 2.72, Glow 2.38.
- LSUN tower: RealNVP 2.81, Glow 2.46.
- LSUN church outdoor: RealNVP 3.08, Glow 2.67.
Glow is better on every dataset in the table. The paper's Table 3 gives Glow's results on 5-bit images: CIFAR-10 1.67, ImageNet 32 by 32 1.99, ImageNet 64 by 64 1.76 and CelebA HQ 256 by 256 1.03. These use a different bit depth, so they are not directly comparable with Table 2. The paper also reports that sampling a 256 by 256 image with its largest models takes under a second on current hardware, with a footnote giving about 130 ms on one 1080 Ti GPU at batch size 1.
Limits. The paper gives no formal guarantee that the learned permutation is better in general, only the experiments above. Sampling uses a temperature, and the authors chose 0.7 for the faces as "a sweet spot for diversity and quality", which means the reported sample quality depends on a tuned setting. The face experiments use the CelebA HQ dataset with a split of 27000 training and 3000 validation images, and 5-bit inputs, which trade a little colour fidelity for visual quality, as the paper states. The attribute editing in Figure 6 relies on averaged latent codes from CelebA labels, a small amount of supervision applied after training.
Reading guide
The paper has a short background section, so read it in this order with the lessons it leans on.
- Section 1 (Introduction): the case for likelihood-based models and the three families. Needs Variational Autoencoder and Generative Adversarial Network for the comparisons.
- Section 2 (Background): the flow formulation and the log-determinant. Needs Normalizing Flow, Change of Variables Formula, Jacobian Matrix and Determinant.
- Section 3 (Proposed generative flow): the three parts of a step. Needs Batch Normalization (the comparison in 3.1), Pointwise (1x1) Convolution, Orthogonal Matrix (the random rotation initialisation), and Affine Coupling Layer.
- Section 4 (Related work): the other flows and the autoregressive alternative. Needs Autoregressive Model.
- Section 5 (Quantitative experiments): the ablation and Table 2. Needs Maximum Likelihood Estimation for the training objective and Gaussian (Normal) Distribution for the prior.
- Section 6 (Qualitative experiments): sampling, interpolation and attribute editing. Needs Latent Variable Model.
- Section 7 and Appendices: the conclusion and hyperparameters. Read the appendix tables for the batch sizes and depths used.
Check yourself
QuestionIn the 1x1 convolution step, the image has h = 4 and w = 4, and det(W) = 3. What is the log-determinant of this layer, in natural log, to two decimal places?Show answer
The log-determinant is h · w · log |det(W)| = 16 × log 3. Since log 3 ≈ 1.0986, the value is about 17.58.
QuestionWhy does the paper parameterise W through its LU decomposition?Show answer
The log-determinant of a general c by c matrix costs O(c³) to compute, while the LU form reduces it to the sum of log absolute values of the diagonal vector s, which costs O(c). The gain grows with c.
QuestionWhy is an affine coupling layer invertible even though the scale and shift come from a neural network?Show answer
The copied half x_b passes through unchanged, so the inverse can recompute the same scale and shift from y_b, which equals x_b. Then it undoes the affine map on the other half. The network itself never needs to be inverted.
QuestionOn the CIFAR-10 numbers in Table 2, how much lower is Glow's bits per dimension than RealNVP's, and in percent of RealNVP's value?Show answer
The difference is 3.49 − 3.35 = 0.14 bits per dimension. As a fraction of RealNVP's 3.49, that is 0.14 / 3.49 ≈ 0.040, or about 4%.
QuestionScenario: a team wants a generative model that gives exact likelihoods and can encode an image into a latent code in one pass. Why might a flow such as Glow fit better than a GAN for this goal?Show answer
A flow is invertible, so it gives exact likelihoods and exact latent inference. The paper points out in its introduction that GANs have no encoder at all to infer latents. Glow therefore fits when a team needs both likelihoods and encoding, though it still has to be trained and checked against the data.
Sources
- Kingma, D. P. and Dhariwal, P. (2018). Glow: Generative Flow with Invertible 1x1 Convolutions. arXiv:1807.03039. https://arxiv.org/abs/1807.03039
- Glow code release, OpenAI. https://github.com/openai/glow