Skip to content
module

RealNVP

13 members
lucid.models.generative.realnvp

RealNVP family — Dinh, Sohl-Dickstein & Bengio, 2016 (affine-coupling flow).

Image Generation
Paper

Dinh, Laurent, Jascha Sohl-Dickstein, and Samy Bengio. "Density Estimation Using Real NVP." International Conference on Learning Representations, 2017.

Overview

RealNVP takes the coupling layer of NICE and makes it scale as well as shift, which is what finally let exact-likelihood flows model natural images. An affine coupling layer splits the input with a binary mask bb and rescales the unmasked half by a learned, input-dependent factor:

y=b⊙x+(1−b)⊙(x⊙exp⁡(s(b⊙x))+t(b⊙x)).y = b \odot x + (1 - b) \odot \Big(x \odot \exp\big(s(b \odot x)\big) + t(b \odot x)\Big).

The Jacobian is still triangular, so its log-determinant is just ∑(1−b)⊙s\sum (1 - b) \odot s — no matter how deep ss and tt are. Unlike NICE's additive coupling this map is no longer volume-preserving, so the flow can concentrate and dilate density where the data needs it rather than relying on one global diagonal scaling.

Two masks exploit image structure. The checkerboard mask is 1 where the sum of the spatial coordinates is odd; the channel-wise mask is 1 on the first half of the channels. Between the two, a squeeze trades space for depth — each 2×2×c2 \times 2 \times c block becomes 1×1×4c1 \times 1 \times 4c, turning an s×s×cs \times s \times c tensor into s2×s2×4c\tfrac{s}{2} \times \tfrac{s}{2} \times 4c — so that channel-wise masking after the squeeze partitions along a different axis than the checkerboard did before it.

The third idea is the multi-scale architecture. Each scale runs three alternating checkerboard couplings, squeezes, runs three alternating channel-wise couplings, then factors out half the dimensions:

h(0)=x,(z(i+1),h(i+1))=f(i+1)(h(i)),z=(z(1),…,z(L)).h^{(0)} = x, \qquad \big(z^{(i+1)}, h^{(i+1)}\big) = f^{(i+1)}\big(h^{(i)}\big), \qquad z = \big(z^{(1)}, \dots, z^{(L)}\big).

Factored-out dimensions are modelled as Gaussians immediately and stop paying compute, so the network spends its depth on the coarse-scale structure that still needs it; the final scale applies four alternating checkerboard couplings and emits the rest. Coupling networks are residual convolutional stacks (ReLU, skip connections) whose ss output is a tanh⁡\tanh scaled by a learned factor — bounded, so the exponential cannot explode early in training.

Because pixel data is bounded and quantised, the model is fitted in logit space: x↦logit(α+(1−2α)x)x \mapsto \mathrm{logit}\big(\alpha + (1 - 2 \alpha) x\big) with α=0.05\alpha = 0.05, whose log-determinant is part of the reported likelihood. RealNVP reaches 3.49 bits/dim on CIFAR-10 with exact inference and exact single-pass sampling — neither of which a VAE or an autoregressive model gives you — and its coupling/multi-scale recipe is inherited almost unchanged by Glow.

Classes

Functions