A mean reduction weights the KL by the input width
shape▲▲△A VAE for images in has a batch of inputs of shape , a code of width , and a Gaussian decoder with , so that is the summed squared error plus a constant. Give the shape of every tensor from the encoder’s output to the loss. Then compare the correct loss with the one written as the mean squared error over all elements plus the KL summed over the code and averaged over the batch. What does the second one train with, and by I.13.T3 what happens to the code?
Hint
A mean over all elements divides by . The KL was divided only by .
Solution
Shapes. The encoder’s last layer returns , split into and , each . The noise and the code are . The decoder returns , compared with the input flattened to . The KL by (I.13.5) is summed over the coordinates to give , as is the squared error over the pixels, and the loss averages both over the batch.
The two losses. The correct negative ELBO, up to a constant, is
The second divides the squared error by and the KL by . Multiplying it by gives the correct reconstruction term plus times the KL. The two have the same minimisers only if .
What happens. In the linear model of I.13.T3 a direction survives only if its variance exceeds . A pixel in has variance at most , so the total variance of all pixels is at most , and no direction exceeds that. Every direction collapses: the encoder returns the prior and the decoder learns the mean image.
A nonlinear VAE is not bound by this exactly, but the pressure is the same, and blurred reconstructions with a KL near zero are the usual symptom. The shapes were all correct. Only the reductions disagreed.