Anomaly detection live
trained on normal cats only. Same idea spots defects on a factory line.
MAAI901 · Deep Learning for Visual Data
Danish · MAAI901 · Tuesday 20 October 2026
scroll, swipe or use the arrow keys ↓
Part 1 · From classification to generation
analogya pet-show judge can’t paint a cat
p(label | image)p(image)
Part 2 · Autoencoders
Part 2 · Autoencoders
illustrationdescribe a face with two numbers (after Deepia's VAE video)
smile 0.80 · hair 0.30
a network gets no names for its axes: it invents its own, for cats
two numbers per face; drawing the face back from a point is a decoder's job
Part 2 · Autoencoders
same encoder, different ending
Part 2 · Autoencoders
analogypacking two weeks of clothes into one carry-on
Like the faces chart, but the network has to find its own two numbers. First, what does it see?
Part 2 · Autoencoders
analogybringing the whole textbook into the exam
12,288 numbers → 2 numbers
loss 0.0 (summed squared error)
undercomplete illustration: the output is the input
Part 2 · Autoencoders
Big codes can copy, so each type adds one rule about z.
A big code is allowed, but a penalty keeps most neurons off. Each one that fires has to earn its place.
Same noisy cat, two models. The denoising AE was trained to predict the clean original. The plain AE was not.
Jiggle the pixels. The bars show how far z moves. The contractive model is punished if a small jiggle moves the code a lot.
Every model in this deck is already convolutional. dae_128 is a convolutional denoising autoencoder.
Part 2 · Autoencoders
analogya test where the question sheet is also the answer key
Part 2 · Autoencoders
analogya ball rolling downhill, one small nudge at a time
a replay of ae_2's training: the loss falls, the cats sharpen, and the latent space organises itself
Part 2 · Autoencoders
analogya security guard who only knows the regulars
12,288 → 64
Live ae_2, ae_16, ae_64 and ae_256. A smaller code is more compression, and a blurrier cat.
Noise is added here. dae_128 was trained to rebuild the clean cat.
ae_2's code is a feature. These are the training cats with the nearest codes. With only 2 numbers they share broad traits like lighting and pose, not the exact cat. Hand z to another model and you can throw the decoder away.
trained on normal cats only. Same idea spots defects on a factory line.
Part 3 · Why autoencoders can't generate
analogyan old map: the cities are drawn, the rest is monsters
in the data: 0 / in the gaps: 0
the decoder never saw anything from the gaps
Part 4 · Variational autoencoders
two papers, one trick: keep the randomness where a gradient can get past it
Part 4 · Variational autoencoders
analogya table of grades and ages: column totals, and one row rescaled
joint: how often a cat and a code go together.
, marginals: add up the other variable, .
code → cat: the decoder.
cat → code: the encoder (the ‘posterior’).
Doing this exactly is impossible, so the VAE guesses it with a simple bell curve. That guess is the ‘variational’ part.
drag across the heatmap: the horizontal slice is p(x | z), the vertical slice is p(z | x)
Part 4 · Variational autoencoders
analogya translator between cat photos and a language we invented
generate = sample the round world, decode into the strange one. The encoder only helps us train.
Part 4 · Variational autoencoders
analogyKL is a leash tying every cloud to the middle of the park
Loss = how badly it rebuilt the cat + how far its cloud drifted from the round blob
ELBO (Evidence Lower Bound) = the official name for this combined score. Loss = −ELBO.
reconstruction: how far the rebuilt cat is from the input
= Kullback–Leibler divergence: how different two distributions are (0 = identical). Here per dimension, 0 only when
Part 4 · Variational autoencoders
analogynot an exact address, a neighbourhood
Part 4 · Variational autoencoders
analogyroll the dice first, then stretch it by σ (sigma) and move it by μ (mu)
Can we backprop through a random sample? No: the gradient stops at the dice.
the encoder really outputs log σ² (log of sigma squared), for numerical stability
Part 4 · Variational autoencoders
KL warm-up lets the cats spread out first; then KL pulls every cloud into one round N(0, 1)
Part 4 · Variational autoencoders
analogya tug of war: rebuild each cat vs pack everyone together
KL = Kullback–Leibler divergence
Part 4 · Variational autoencoders
either way, the plain AE’s gaps were never trained
grids: bigger AE and VAE trained overnight (10M weights, 100 epochs), samples precomputed. The map: the small live VAE.
Part 4 · Variational autoencoders
bigger AE and VAE (10M weights), walks precomputed
pixels stack two ghost cats · the plain AE keeps one cat but glitches between codes · the VAE morphs smoothly, but softer
Part 5 · Limitations, alternatives and wrap-up
MSE's best guess is the average of the sharp cats that fit, and the KL term also caps how much detail the code can hold
Part 5 · Limitations, alternatives and wrap-up
analogya forger and a detective
Part 5 · Limitations, alternatives and wrap-up
| VAE | GAN | Diffusion |
|---|
Not a GAN photograph. This repo has no GAN checkpoint, so Gary is our VAE decoding one code nine times with a little jitter. A real GAN sample would be sharper. This only shows mode collapse: one picture, over and over.
Part 5 · Limitations, alternatives and wrap-up
Feed in a label too, then ask for a tabby. A plain VAE can’t take requests: you get a random cat.
A bigger KL weight: a tidier, more disentangled latent space, where each axis means one thing. The cost: blurrier cats.
A fixed dictionary of codes instead of a cloud, like paint-by-numbers. A close cousin (dVAE) powered the first DALL-E.
Its VAE squeezes a 512×512 image into a latent 48× smaller. Diffusion denoises there, and a VAE decoder paints the final image.
Part 5 · Limitations, alternatives and wrap-up
analogyFID compares two crowds, not two faces
Reconstruction: PSNR on the 64 held-out cats, computed live. Higher is better.
Generation has no answer key, so compare clouds: FID runs real and generated images through a pretrained network and measures how far apart the two clouds of features are. Lower is better. This deck shows reconstruction, not FID.
a model you can’t measure is a model you can’t trust
Part 5 · Limitations, alternatives and wrap-up
Part 5 · Limitations, alternatives and wrap-up
Questions?
Cat faces: fferlito/Cat-faces-dataset on GitHub
AFHQ: Choi et al., StarGAN v2 (CVPR 2020)
Built with PyTorch and ONNX Runtime Web
References
3Blue1Brown, Neural networks series (YouTube)
Deepia, Variational Autoencoders | Generative AI Animated (YouTube)
Kingma & Welling, Auto-Encoding Variational Bayes (2013)
autoencoders.danishali.dev · github.com/Danish12196/vae-presentation
β is the weight on the KL term. β = 0 is a plain autoencoder: the codes scatter. β = 1 is an ordinary VAE. β = 4 packs every code toward zero, and the cats get blurrier.
That is the slider on “Turning the KL dial”: beta 0, 0.1, 1 and 4, on the same cats.
getting ready…