Three ways to look inside an image classifier
A convolutional network turns a photo into a stack of feature maps, one per channel, and each channel's value at a position says how strongly something it detects is present there. What that something is, nobody told the network. This tab asks three questions of a trained one, torchvision's GoogLeNet (Inception v1, 6,624,904 parameters, 69.8 % top-1 on ImageNet, with weights torchvision ported from the original paper): what image would make a channel fire as hard as it can, which real photos make it fire most, and, for a given class, where in the photo the network found its evidence.
The page reads six stages from input to output: the third convolution (conv3) and the inception blocks 3b, 4b, 4d, 4e and 5b. Each later stage sees more of the image: one position of conv3 depends on a 19-pixel square of the input, one of 4b on 139 pixels, and one of 5b on 379, more than the 224-pixel input itself. The number under each row name in the Feature visualization, stage by stage panel is that size.
Optimizing an image for one channel
Feature visualization turns the network around: instead of computing activations from an image, it computes an image from an activation. Start from noise , measure the channel's mean activation over all positions of its map, and follow the gradient uphill:
Each of the 48 pictures on the page is 512 Adam steps at learning rate 0.05, one batch of eight per stage on the Mac's GPU. The The optimization strip shows one channel's picture at steps 0, 16, 64 and 256: a grey field gains faint structure by step 16, then the pattern that the final picture repeats across the frame. The Objective over the optimization chart below follows over the 512 steps.
Why the picture needs regularizing
Optimized directly, pixel by pixel, the same objective finds something else. The raw pixels picture next to each visualization is the same optimization with the image held as raw pixels (through a sigmoid, from Gaussian noise) and nothing else. It drives the channels higher still (the 5b channels reach 34 to 62, against 20 to 34 for the regularized pictures), but what it finds looks like coloured static: high-frequency patterns that work only at one exact alignment with the network's strides, the same weakness adversarial examples use. Six of the 48 channels (4b channel 0 and five of 4e's) do not fire anywhere on the starting noise, so their gradient is exactly zero and the raw optimization never moves.
Lucid, the library behind Olah et al.'s Feature Visualization, adds two kinds of prior, and the page uses its defaults. The image is described by its Fourier coefficients, each scaled by so that low frequencies change as easily as high ones, with the colour channels decorrelated by the square root of ImageNet's colour covariance; a sigmoid keeps pixels in . And before every step the image is transformed at random: padded by 12 grey pixels, shifted by up to 8 pixels, scaled by 0.9 to 1.1, rotated by up to 10° and shifted again by up to 4. A pattern that only works at one exact position, size and angle does not survive this, so what remains is what the channel responds to robustly. Different priors give different pictures, so the pictures say as much about the priors as about the channel.
From colours and edges to parts
Read the rows from top to bottom. The conv3 channels want flat colours, colour contrasts and oriented stripes; 3b's want small repeated textures, dots and grids; 4b's and 4d's want larger patterns, petal, leaf and fur textures and blob-like shapes; 4e's show parts, eye-like rings, feathers and scales; and 5b's mix whole object-like fragments, the stage closest to the 1,000 classes. These are the first eight channels of each stage, not picked for looking good, so some are hard to name.
The pictures are also stronger than anything the photos contain. The page runs each one, as it shows it, back through the network: in 38 of the 48 channels the picture's mean activation over all its positions is higher than the single strongest position on any of the 3,000 photos. A feature visualization is an exaggeration of what the channel responds to, a superstimulus, not a typical input.
The photos that fire a channel
The second view needs no optimization. The page runs 3,000 photos from the Open Images validation split (every one CC BY 2.0, each credited on hover) through the network, keeps for each channel its strongest position on each photo, and shows the six photos where that value is highest, cropped around the position to roughly the input square it depends on. The bars under them count the photos at each strength: most photos barely touch most channels.
Where the picture and the photos agree, the channel has a fair claim to a name. Where they do not, it may respond to several unrelated things: 4e's channel 0 is strongest on a vintage car, an iPod, a wall socket and a phone. Olah et al. call these channels polysemantic, the same problem the SAE features tab meets in a language model.
Grad-CAM: where it looked for a class
Grad-CAM asks the opposite question: not what a channel wants, but which part of one photo pushed one class's score. It takes the last inception block's output (1,024 channels on a 7 × 7 grid, each cell covering 32 × 32 input pixels), weights each channel by how much the class score (before the softmax) rises with it on average, and keeps the positive part:
The page upsamples to the photo bilinearly. On the rider, mountain bike (p 0.66) lights the bike and crash helmet (0.12) the head. Beside a dalmatian sits a white dog: dalmatian (0.27) covers the spotted dog, kuvasz (rank 3, a large white breed) the other one. ImageNet has no wildebeest, so on a herd of them GoogLeNet answers water buffalo (0.52), and its map sits on the wildebeest in front; zebra, only sixth, finds the zebras behind. On an old photo of logging with horses the top class is worm fence (0.47), and the map shows the stacked logs it took for one; sorrel, ImageNet's horse class, is ranked 175th, yet its map finds the horses. On a yawning cat the answer is hamster (0.50), and the map shows it looked at the right place, the cat's face, and drew the wrong conclusion.
A heatmap like this says where the gradient flows, not why. Adebayo et al. showed that some saliency methods produce similar maps even for a network with random weights; Grad-CAM passes their test, but at 7 × 7 it can only say roughly where.
Papers
- Feature Visualization Feature visualization by optimization on GoogLeNet: the objectives, the Fourier and colour-decorrelated parametrization and the transformation robustness this tab uses, and the dataset examples to set beside it.
- Grad-CAM: Visual Explanations from Deep Networks via Gradient-based Localization Weights the last convolutional layer's channels by the pooled gradient of a class score to show where a network found that class.
- Going Deeper with Convolutions GoogLeNet (Inception v1), the network this tab looks inside: inception blocks of parallel 1 × 1, 3 × 3 and pooling branches.
- Visualizing and Understanding Convolutional Networks Showed each layer's strongest dataset patches and projected them back to pixels, finding edges in early layers and object parts in later ones.
- Deep Inside Convolutional Networks: Visualising Image Classification Models and Saliency Maps Class visualizations by gradient ascent on the input and saliency maps from the input gradient, the methods both halves of this tab grew from.
- Learning Deep Features for Discriminative Localization Class activation maps: localizing a class with a network's last convolutional features, which Grad-CAM generalized to any architecture through gradients.
- Sanity Checks for Saliency Maps Tests whether a saliency map depends on the model's weights and data at all; several popular methods fail, Grad-CAM passes.
- The Open Images Dataset V4: Unified image classification, object detection, and visual relationship detection at scale The photos the page runs through the network: CC BY 2.0 images from Flickr with human-verified labels.