Interactive demo · Probabilistic Machine Learning · Chapter 14

Inverting a CNN: what image makes the classifier sure?

A classifier p(y | x) is not a generative model, but with a prior p(x) over images it defines one, p(x | y) ∝ p(x) p(y | x), and gradient steps on the pixels sample or optimise it (Equations 14.28 to 14.30). The network here is a small two-convolution CNN trained on MNIST digits (97.8% test accuracy); its weights are in this page. Choose a target class and a prior and move the sliders: with no prior the image becomes confident but looks like noise; the Gaussian prior (14.29) keeps pixel values small; the total-variation prior (14.31) removes high-frequency speckle; Langevin noise gives a different image each seed.

Target class c

Prior p(x)

Start from

Steps shown T

Prior step ε1

TV weight λ

Likelihood step ε2

Langevin noise ε3

Try these

The update is xt+1 = xt + ε1∇log p(xt) + ε2∇log p(y=c | xt) + ε3nt with nt standard normal noise (seeded). Gaussian prior: ∇log p(x) = −x. TV prior: log p(x) = −λ TV(x) with TV the sum of squared neighbouring differences (14.31). The gradient with respect to the pixels is computed by backpropagation through the convolutions, ReLUs and max pools. Pixels are not clipped to [0, 1]. "Another digit" starts from the first test image of class c + 1 (mod 10), so the run turns one digit into another. The images are shown with their own contrast range.

In the lecture notes