RealNVP
13 memberslucid.models.generative.realnvpRealNVP family — Dinh, Sohl-Dickstein & Bengio, 2016 (affine-coupling flow).
Dinh, Laurent, Jascha Sohl-Dickstein, and Samy Bengio. "Density Estimation Using Real NVP." International Conference on Learning Representations, 2017.
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 and rescales the unmasked half by a learned, input-dependent factor:
The Jacobian is still triangular, so its log-determinant is just — no matter how deep and 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 block becomes , turning an tensor into — 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:
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 output is a 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: with , 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
realnvp_celeba→ RealNVPModelConstruct the RealNVP flow for the CelebA 64 x 64 setup.
realnvp_celeba_gen→ RealNVPForImageGenerationRealNVP generator for CelebA 64 x 64.
realnvp_cifar→ RealNVPModelConstruct the RealNVP flow for the CIFAR-10 setup.
realnvp_cifar_gen→ RealNVPForImageGenerationRealNVP generator for CIFAR-10 (bits/dim loss + .generate()).
realnvp_imagenet32→ RealNVPModelConstruct the RealNVP flow for the Imagenet 32 x 32 setup.
realnvp_imagenet32_gen→ RealNVPForImageGenerationRealNVP generator for Imagenet 32 x 32.
realnvp_imagenet64→ RealNVPModelConstruct the RealNVP flow for the Imagenet 64 x 64 setup.
realnvp_imagenet64_gen→ RealNVPForImageGenerationRealNVP generator for Imagenet 64 x 64.
realnvp_lsun→ RealNVPModelConstruct the RealNVP flow for the LSUN 64 x 64 setup.
realnvp_lsun_gen→ RealNVPForImageGenerationRealNVP generator for LSUN 64 x 64.