Autoencoding GANs: AAE and α-GAN
How to give a GAN an encoder and a VAE sharp samples: a discriminator on codes matches their cloud to the prior, a discriminator on images removes the blur, and Wasserstein critics make training steadier.
What each family is missing
The topic Wasserstein GANs and Lipschitz constraints gave the generator a loss whose gradient survives when the samples are far from the data. Two things are still missing, and the VAE has both. A GAN has no encoder: to find the code of a real photograph, StyleGAN included, one has to solve an optimization problem for every image. And nothing ties a GAN to each training image, so it can quietly drop modes. The VAE of The reparameterization trick has an encoder, and every training image must be rebuilt from its code. But its samples are blurry.
Can one model keep the encoder and the coverage of a VAE and the sharpness of a GAN? Start from the ELBO and ask which of its parts we actually need:
With a Gaussian decoder the first term is a squared error. It gives coverage, since no image may be ignored. Its optimum, the average of the images that fit one code, gives the blur.
The KL term is worth splitting. Let be the aggregate posterior, the distribution of codes over the whole dataset. Write the ratio inside the logarithm as and average each factor's logarithm over images and codes. The result:
The first part, the mutual information between images and codes, charges every image for an informative code, although reconstruction needs exactly that information. Only the second part matters for sampling: a prior sample decodes well only if it lands where the codes of real images lie.
The models of this topic keep the encoder and the reconstruction term. The marginal mismatch, and then the blur, they hand to discriminators.
Adversarial autoencoders: a discriminator on codes
The adversarial autoencoder (AAE) of Makhzani et al. (2015) is an ordinary autoencoder with a third network attached to its code. The encoder maps an image to a code . The generator , which is the decoder, maps it back to . The code discriminator tells codes from samples of the prior . For a deterministic encoder, is simply the distribution of with .
One change of notation holds for the whole topic. Both discriminators here output a real-valued score, a logit, and of the score is the probability "real". GANs as a two-player game already computed its losses from logits in code. Later the same networks will become Wasserstein critics.
Each minibatch has two phases. In the reconstruction phase, and minimize the squared error . In the regularization phase, learns to call prior samples real and codes fake:
Then the encoder, the generator of this small GAN, is updated to fool it, for example with the non-saturating loss .
sees one code at a time and never learns which image it came from. So it compares the whole cloud of codes with the prior. The optimal discriminator of the GAN topic, applied to codes, gives . Inverting the sigmoid turns this into a score:
A classifier's logit estimates a log density ratio. This density-ratio trick drives every model below. Substitute into the minimax loss, as in the GAN topic, and the encoder minimizes . Compared with the ELBO, the AAE keeps the marginal mismatch, measured by JS instead of KL, and drops the penalty on informative codes.
The discriminator needs only samples of the prior, never its density, so any prior we can sample will do. With a 2-D Gaussian prior, the codes of held-out MNIST digits fill the prior without gaps, while a VAE with the same architecture leaves holes (Makhzani et al., 2015, Figure 2). The decoder, however, still learns from a pixel error alone, so its outputs are as blurry as a VAE's.
α-GAN: a discriminator on images as well
The α-GAN of Rosca et al. (2017) starts again from the ELBO and replaces each term with something a discriminator can estimate.
The KL term becomes a code discriminator, as in the AAE. By the density-ratio trick,
This is the marginal KL, the part that sampling needs.
The likelihood term gets two candidates that fail in opposite ways. The first is a Laplace likelihood over pixels:
Its negative logarithm is the reconstruction loss plus a constant. It covers every training image, but it still blurs. Per pixel, the derivative of in is , so the optimum sits where half of the plausible values lie on each side. A squared error would pick their mean instead.
The second candidate is a synthetic likelihood: the score of an image discriminator trained to tell data from decoded images. It gives sharp images but, like any GAN, allows mode collapse. α-GAN takes both. With a deterministic encoder, and maximize
Why plain scores rather than logarithms of probabilities? On the generator side Rosca et al. use , the sum of the non-saturating and the minimax losses. Since , the sum is exactly , minus the logit. Its gradient with respect to the logit is for every , so it never saturates. The minimax part alone has gradient , which vanishes when the fakes are confidently rejected.
Why all three terms are needed
Each network minimizes its own loss while the others stay fixed. With and :
The image discriminator receives samples , , as fakes next to the reconstructions. So samples are pushed toward the data, not only reconstructions.
Why are all three parts needed? Suppose two conditions hold exactly: the codes are distributed as the prior, , and every image is rebuilt, . Take . Then and have the same distribution, and the same is applied to both, so is distributed as . That is itself, distributed as . The samples are distributed as the data.
Each term guards one condition. The code discriminator enforces the first. Without it the codes could sit anywhere in , and prior samples would land where never learned anything, the failure of a plain autoencoder (see Autoencoders). The reconstruction term enforces the second, and it is what discourages mode collapse: a generator that dropped a mode could not rebuild that mode's images, and its loss would grow. Both conditions hold only approximately, so the image discriminator checks the samples directly. By judging reconstructions as well, it pushes toward a sharp image near instead of the blurry per-pixel optimum.
On CelebA and CIFAR-10, α-GAN was competitive with DCGAN and WGAN-GP, but not uniformly better.
α-WGAN: two Wasserstein critics
The generator-side losses of α-GAN are already minus a score, which is the form of the WGAN generator loss. Only the training of the discriminators separates α-GAN from a Wasserstein version. Kwon, Han and Kim (2019) keep the encoder and generator losses and train both and as critics with the gradient penalty of Wasserstein GANs and Lipschitz constraints. With the penalty weight, the three losses are
Each penalty is the WGAN-GP one, taken at random points between a real input and a fake one: between an image and a reconstruction or sample for , between a prior sample and a code for . Kwon et al. use .
The image critic's loss is two WGAN comparisons sharing one critic, reconstructions against data and samples against data. Hence the factor 2 on the real term. The encoder and the generator are trained as one network on , and each term sends gradients to every network it depends on.
Why a Wasserstein critic for the codes too? Early in training, the codes of a deterministic encoder can sit far from the prior. A classifier then separates them easily, and an optimal one is constant on the codes: the case of non-overlapping supports from GANs as a two-player game, where the gradient vanishes. Kwon et al. made the change because their model, trained on 3D brain MRI volumes, was unstable with the classifier losses.
Each player gets its own optimizer over its own parameters: one for and together, one for , one for . In the critics' steps, reconstructions, samples and codes enter as constants.
A code critic in one dimension
A one-dimensional example shows what each kind of code critic tells the encoder. Take and the prior , and suppose every code is shifted by , so .
The classifier's optimal score is the log ratio of the two densities:
With the classifier held fixed, the encoder minimizes , a function of the shift .
For the Wasserstein critic, take . It is 1-Lipschitz, and . By the Kantorovich–Rubinstein duality, is the largest such difference, so . Moving every point by is a transport plan of cost , so . Hence , and is an optimal critic. Its gradient has norm 1 everywhere, so .
With this critic held fixed, the encoder's loss is . Its derivative with respect to the shift is 1, whatever the shift.
Both critics point the codes toward the prior. The question is how hard each one pushes as the codes get close.
Interpolation: lerp or slerp
An encoder lets us walk between two real images. Encode them, and , move along a path and decode . The simplest path is linear interpolation (lerp), for .
Spherical linear interpolation (slerp) follows a great circle instead (Shoemake, 1985; White, 2016). With the angle between and ,
For two vectors of equal length , the point turns from toward by the angle and keeps the length .
Why does that matter? In high dimension, samples of lie in a thin shell. is a sum of squared standard normals, with mean and variance , so the length is close to , with a spread of about . Two independent samples are nearly orthogonal: their cosine has standard deviation . For , a sample has length , while the lerp midpoint of two samples has length about . That is 4.7 spreads inside the shell, a region that training on almost never visits.
High density is not the same as typical. The log-density of is plus a constant, so the midpoint is 32 nats more probable per unit volume than a typical sample. Yet points of that length almost never occur, because there is little volume near the centre. A generator learns what the prior actually produces.
In two dimensions, take and . The lerp midpoint has length . Slerp has , both coefficients at equal , and the midpoint has length 3.
For an autoencoding GAN the endpoints are codes of real images. If the code critic has matched to the prior, the same argument applies. But slerp keeps only the length typical. It does not steer the path around holes in , which White calls dead zones.
Where it breaks, and what comes next
Rosca et al. found every model they tested, α-GAN and the baselines alike, sensitive to the architectures: minor changes led to catastrophic mode collapse. An autoencoding GAN has four networks, three optimizers, the weights and and the update ratios. A large brings back the blur of the pixel loss; a small one weakens the guard against mode collapse.
The code size shows the tension concretely. Suppose the images lie on a surface described by coordinates, and a deterministic encoder is Lipschitz in them. If , its codes form a set of zero volume in , and the prior gives that set probability zero. The supports of and then do not overlap, and prior samples land off the surface of codes, where never learned anything. The AAE paper ties the code size of a deterministic encoder to the intrinsic dimension of the data, 5 to 8 for MNIST. For large codes it recommends a stochastic encoder, whose noise fills the missing directions. The code cannot be too small either: if two images share a code, can return only one of them, and the reconstruction term grows. Only held-out reconstructions and samples tell where the workable range lies.
| WGAN-GP | AAE | α-GAN | α-WGAN | |
|---|---|---|---|---|
| Networks | , critic | , , | , , , | , , , |
| Codes matched to the prior by | — | classifier | classifier | WGAN-GP critic |
| Pixel term | none | squared error | ||
| Image adversary sees | samples | — | reconstructions and samples | reconstructions and samples |
| Can encode real images | no | yes | yes | yes |
α-GAN matches images to their reconstructions point by point, but codes only in distribution. Rosca et al. note that adding a pointwise code reconstruction would make it resemble CycleGAN. The next extension, CycleGAN: unpaired image-to-image translation, replaces the code space with a second image domain: two generators translate between domains without paired examples, and a cycle of reconstructions ties every output to its input.
The main line goes the other way. Here the encoder only approximately inverts the generator, and there is still no likelihood. The change of variables makes the encoder the exact inverse of the generator, with the same dimension in and out, and gets the likelihood exactly: normalizing flows.
Check your understanding
The same questions as in Pulse. Answers are shared between modes.
Answers are saved on the server and tied to this browser until you sign in.