Back to paper library
Paper notesarXiv 2013ECCV 2014

ZFNet

The View Inside the Black Box

Original paper

Visualizing and Understanding Convolutional Networks

Paper authors

Matthew D Zeiler · Rob Fergus

Publication
ECCV 2014Conference
First submitted to arXiv
arXiv:1311.2901
Cite this paper · BibTeX

The citation identifies the linked source version. It cites the original paper and its authors.

@misc{classiccnnszfnet2013,
  title = {{Visualizing and Understanding Convolutional Networks}},
  author = {Matthew D Zeiler and Rob Fergus},
  year = {2013},
  eprint = {1311.2901},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1311.2901}
}
On this page

In the 2012 ImageNet competition, AlexNet pushed the top-5 error rate down to 16.4%. Second place was at 26.2%.

That's a gap of nearly ten percentage points. Overnight, convolutional networks went from a niche technique to something every lab wanted to try.

But as accurate as the model was, nobody could say why. To improve it, all you could do was change the number of layers, tweak a filter size, train for a week or two, and see whether the score went up.

Matthew Zeiler and Rob Fergus of New York University released this paper in November 2013, and in the introduction they bluntly call this state of affairs trial-and-error. They wanted to understand the model first, then fix it based on the problems they saw.

Defining the Problem

Understanding the first layer of a convolutional network isn't hard. First-layer filters act directly on pixels, so if you draw the weights as small images, you can see them looking for horizontal lines, diagonal lines, or blobs of a certain color.

From the second layer on, that stops working. Second-layer filters act on the output of the first layer, so drawing their weights just gives you a pile of numbers with no visible meaning. The higher you go, the more abstract what each unit sees, and the harder it is to trace back to the original image.

A few approaches already existed. Erhan et al. ran gradient ascent in image space to find the input that maximizes a unit's activation, but the result depended on initialization and said nothing about which variations the unit tolerates. Le et al. computed the Hessian numerically around the optimal input to estimate invariances, but higher-layer invariances are complex, and a quadratic approximation can't capture them. Donahue et al. simply found the image patches that strongly activate higher layers, but you still couldn't tell which structures within a patch were the ones that mattered.

The authors wanted to take a real image and an activation in an intermediate layer, project that activation back into pixel space, and see clearly which structures in this image make it light up.

Solving the Problem

Walking Backward Through a Convolutional Network

The authors borrowed the Deconvolutional Network (deconvnet) they had proposed in 2011. The original deconvnet was an unsupervised learning model; here it isn't trained at all. It serves only as a probe, attached alongside a convolutional network that has already been trained.

The top half shows two side-by-side pipelines. On the right is one convolutional network layer, running bottom to top: the pooled input from the layer below goes through convolutional filtering F, ReLU, and max pooling, with the locations of the maxima recorded as switches. On the left is a deconvnet layer, running top to bottom: the reconstruction from the layer above goes through unpooling, ReLU, and filtering with the transpose of F, giving the reconstruction for the layer below. The bottom half illustrates unpooling: pooling records where the maximum sits in each colored region, and unpooling puts the values from the layer above back in those locations
Figure 1 from the paper, excerpted from page 3 of the v3 PDF. In the top half, the right side is one convolutional network layer and the left side is the deconvnet layer attached to it; the bottom half illustrates unpooling.

Start with the right side of the top half, where one layer of the convolutional network runs bottom to top, through filtering (FF), ReLU, and max pooling in that order. The deconvnet on the left runs top to bottom and reverses these three steps, applying unpooling, ReLU, and filtering with the transposed filters (FTF^T) in that order.

Here's how it's used:

  1. Feed an image into the convolutional network and compute the feature maps at every layer.
  2. Pick one activation in some layer and set every other activation in that layer to zero.
  3. Hand this feature map, now holding a single activation, to the deconvnet and reconstruct downward layer by layer until you reach pixel space.

Of the three backward steps, unpooling is the one that needs the most explanation.

Unpooling Has to Remember Where the Max Was

Max pooling throws information away. A 2×22\times2 block keeps only its maximum, and the other three numbers are gone, so the operation has no inverse.

The authors' solution is to record, on the way up, which cell held each block's maximum. These records are called switches.

To trace one activation, set the other activations in that layer to zero, then use the switches to put the value reconstructed from the layer above back where the maximum originally was; every other position stays zero.

That's unpooling, which uses the positions recorded on the way up to put the upper layer's reconstruction back in the right place. The switches belong to this particular input image, so as the reconstruction continues downward, the result looks like a small piece of the original image and keeps the structures that made this activation light up.

The remaining two steps, ReLU and filtering, are much simpler.

  • ReLU: feature maps in the convolutional network are always non-negative after ReLU, so each layer's reconstruction also goes through ReLU again to stay non-negative.
  • Filtering: use the transpose of the same filters, which in practice means flipping each filter vertically and horizontally. It's applied to the rectified reconstruction, not to the original output of the layer below.

The authors also point out that these projections aren't samples generated by the model; no generative model is involved anywhere. They only tell us which parts of this input contribute to the chosen activation.

The Model Under Observation

The model the authors observe closely resembles AlexNet. It has eight layers, five convolutional and two fully connected, followed by a softmax. To split across two GPUs, AlexNet had several convolutional layers connect only to the feature maps on the same GPU; here those layers connect to all the feature maps, and the model is trained on a single GTX 580 for 70 epochs, which takes about 12 days.

Visualization was already useful during training. A few first-layer filters had especially large values and dominated the whole layer ((a) in Figure 6, later on). The authors' remedy is to cap the filters' magnitude, scaling any convolutional filter whose RMS exceeds 10−110^{-1} back to that radius. The authors say this matters especially in the first layer, because input pixels fall roughly in [−128,128][-128, 128].

What Each Layer Sees

Layer 1 shows several groups of filter patterns; layers 2 to 5 each have many 3×3 grids, with gray deconvnet projections on the left and the corresponding color patches from the original images on the right. Layer 2 is mostly edges and color blobs, layer 3 shows textures such as meshes and text, layer 4 has dog faces and bird legs, and layer 5 shows whole objects such as keyboards and dogs
Figure 2 from the paper, excerpted from page 4 of the v3 PDF. For each feature map in layers 2 to 5, the 9 strongest activations across the validation set are shown; the small gray images are deconvnet projections, and the small color images beside them are the corresponding original image patches.

Read this figure in pairs. The gray projections draw only the structures that make the activation light up, while the image patches next to them show the original image.

Here's how the authors describe each layer:

  • Layer 2: corners, plus combinations of edges and colors.
  • Layer 3: more complex invariances, picking up similar textures such as mesh patterns and text.
  • Layer 4: starts to be class-specific, such as dog faces and bird legs.
  • Layer 5: entire objects, tolerating large variations in pose, such as keyboards and dogs.

The benefit of reading in pairs is clearest at layer 5, row 1, column 2. The 9 image patches seem to have nothing in common, yet the projections show that this feature map is actually looking at the grass in the background, not the foreground objects. From the image patches alone, you'd think this unit was looking at random things.

The authors also tracked how features change during training. Lower layers converge within a few epochs, while upper layers only take shape around epoch 40 or 50. Their conclusion is that the model needs to be trained until it fully converges.

Another set of experiments measured how translation, scaling, and rotation affect the features. Small transformations change the layer 1 feature vectors dramatically; by layer 7 the effect is much smaller, and roughly linear for translation and scaling. The final output is stable under translation and scaling but not under rotation, unless the object itself is rotationally symmetric.

Fixing the Architecture with What You See

This is where visualization is most practical. The authors pull out AlexNet's layers 1 and 2 for a look:

Five sets of filter visualizations. (a) is layer 1 without the cap on filter magnitude, with one especially bright square; (b) is AlexNet's layer 1, (c) is the modified layer 1; (d) is the projection of AlexNet's layer 2, (e) is the projection of the modified layer 2
Figure 6 from the paper, excerpted from page 7 of the v3 PDF. (a) Layer 1 without the cap on filter magnitude; (b) AlexNet's layer 1; (c) the modified layer 1; (d) AlexNet's layer 2; (e) the modified layer 2.

First compare (b) and (c). AlexNet's first-layer filters mix extremely high- and extremely low-frequency patterns, with very little in the mid frequencies, plus some “dead” filters that do almost nothing. Then compare (d) and (e), where the projections of AlexNet's layer 2 show traces of aliasing.

The authors trace the problem to the first layer. AlexNet uses 11×1111\times11 filters with stride 4, which they change to 7×77\times7 with stride 2.

How can stride cause aliasing? Stride is just the sampling interval. Take a stripe pattern that repeats every 5 pixels. Sampling every 2 pixels still keeps this fast variation; sampling every 4 pixels turns it into a wide stripe that repeats every 20 pixels. No such stripe exists in the original image; it is a false pattern caused by sampling too sparsely.

AlexNet's first-layer filters already carry a good deal of high-frequency content. When the resulting feature maps are then sampled at stride 4, the high-frequency parts can fold into false low-frequency patterns that get passed on to the next layer. This one-dimensional example is our own illustration; the paper itself points out the phenomenon through the projections, and the second layer after the architecture change, (e), is much cleaner, with no visible traces of aliasing.

More importantly, classification performance improves as well; we'll see the numbers in the discussion.

Cover a Patch and Watch the Classifier

Projections answer “what is this feature looking at?” The authors also wanted to know whether the classifier is really finding the object or just guessing from the background.

They take a gray square and slide it across the image step by step, covering different positions. At each position they record the total activation of the strongest layer 5 feature map and the classifier's output.

A row of five panels. (a) is a Pomeranian with a tennis ball in its mouth, with a gray occluding square on the image; (b) is a heat map of how occluder position affects the total activation of the strongest layer 5 feature map, blue over the dog's face; (c) is the projection of this feature map; (d) is a heat map of the correct-class probability, lowest over the dog's face; (e) is the most probable class at each occluder position, mostly Pomeranian, with a few cells near the dog's face switching to tennis ball, Pekinese, or Keeshond
Figure 7 from the paper (first row), excerpted from page 7 of the v3 PDF. (a) The input image and the gray occluding square; (b) the effect of occluder position on the total activation of the strongest layer 5 feature map; (c) the projection of this feature map; (d) the probability of the correct class; (e) the most probable class at each occluder position.

This is a Pomeranian holding a tennis ball in its mouth. The blue regions in (b) and (d) both fall on the dog's face. Cover the face, and the strongest layer 5 feature weakens and the probability of “Pomeranian” drops sharply. (e) is more interesting. At most positions the prediction is Pomeranian, but when the dog's face is covered while the tennis ball is still visible, the model changes its answer to “tennis ball.”

The other two rows of the same figure remind us that the strongest feature and what the classifier relies on aren't necessarily in the same place. The second row is a race car: the strongest layer 5 feature falls on the text on its body, but the classifier is most sensitive to the wheel. The third row contains several objects: the strongest feature picks out the faces, but the classifier is most sensitive to the dog, which the authors explain by the classifier using many feature maps at once.

Correspondence Across Images

The last analysis gets mentioned less often. Traditional recognition methods often have an explicit correspondence mechanism, such as knowing the relative positions of the eyes and nose on a face. Deep models have no such design, and the authors wanted to know whether they build correspondence implicitly.

They take 5 frontal images of dogs, cover the same part in each one (say, the left eye in all of them), compute the change in features before and after occlusion, and then check whether the signs of these changes agree across the 5 images. The metric is the Hamming distance between the sign patterns of each pair; lower means covering the same part produces more consistent changes:

Table: Numbers excerpted from Table 1 of the paper.
Occluded partLayer 5Layer 7
Right eye0.067 ± 0.0070.069 ± 0.015
Left eye0.069 ± 0.0070.068 ± 0.013
Nose0.079 ± 0.0170.069 ± 0.011
Random location0.107 ± 0.0170.073 ± 0.014

At layer 5, the scores for the eyes and nose are all lower than for random locations, which the authors take to mean that the model establishes some degree of part correspondence at this layer. At layer 7 the scores are close to one another; the authors speculate that the upper layers are busy telling different dog breeds apart.

Discussion

ImageNet 2012

The authors first reproduce AlexNet with its original architecture, landing within 0.1% of the original paper's validation error. Then they switch to the modified architecture:

Table: Error rates (%) excerpted from Table 2 of the paper, omitting the AlexNet entries trained on both the 2011 and 2012 training data.
ModelVal top-1Val top-5Test top-5
AlexNet, 1 model40.718.2—
AlexNet, 5 models38.116.416.4
This paper, 1 model38.416.5—
This paper, 5 models36.715.315.3
This paper, 6 models (including the version with widened middle layers)36.014.714.8

For a single model, validation top-5 error drops from 18.2% to 16.5%; combining 6 models gives a test top-5 error of 14.8%. The authors also note in a footnote that this result had already been surpassed by entries in that year's ILSVRC 2013.

Which Layers Hurt Most When Removed?

Next, working on AlexNet's architecture, the authors remove some layers entirely and retrain from scratch:

Table: Error rates (%) excerpted from the top half of Table 3 of the paper.
ChangeTrain top-1Val top-1Val top-5
Original architecture (reproduced)35.140.518.1
Remove layers 3 and 441.845.422.1
Remove layer 727.440.018.4
Remove layers 6 and 727.444.822.4
Remove layers 3, 4, 6, and 771.171.350.1

The fully connected layers 6 and 7 hold most of the model's parameters; removing them raises val top-1 error from 40.5% to 44.8%, and removing the two middle convolutional layers raises it to 45.4%. Taken separately, both costs are smaller than you'd expect. Remove both groups together, leaving the network with only 4 layers, and the error jumps all the way to 71.3%. The authors therefore conclude that what matters is a certain minimum depth, not any one particular section of layers.

Running the same experiments on ZFNet's own architecture shows that making the fully connected layers larger or smaller has little effect. Widening layers 3, 4, and 5 to 512, 1024, and 512 feature maps lowers val top-1 from 38.4% to 37.5%. If the fully connected layers are also enlarged to 8192 units at the same time, training error falls to 10.0% but validation error climbs back to 38.3%; the model starts to overfit.

Switching Datasets

The authors also wanted to know whether features learned on ImageNet carry over to other datasets. They freeze layers 1 through 7 and retrain only the final softmax on the new dataset. To keep test data from leaking into training, they first found the 44 images Caltech-101 shares with ImageNet and the 243 that Caltech-256 shares, removed them from the ImageNet training set, and retrained the ImageNet model.

  • Caltech-101 (30 training images per class): 86.5%, against 81.4% for the best previous result, by Bo et al. The same network trained from scratch on Caltech-101 gets only 46.5%.
  • Caltech-256 (60 per class): 74.2% versus 55.2%. With just 6 training images per class, it already beats Bo et al.'s result with 60.
  • PASCAL VOC 2012: a mean of 79.0%, 3.2 percentage points below the best method at the time, though it beats that method on 5 classes. PASCAL images are mostly full scenes containing several objects, while the model can output only one class; the authors see this as one reason it falls behind.

Around the same time, work by Donahue et al. was also exploring how well convolutional features generalize. On this basis, the authors question whether benchmarks with training sets of fewer than ten thousand images can still compare methods properly.

Are Higher Layers More Useful?

Table 7 of the paper cuts the pretrained model off at different layers and puts a linear SVM, or a softmax, on top:

  • Caltech-101: 44.8% using only layer 1, then 66.2%, 72.3%, and 76.6% in turn, reaching 86.2% at layer 5 and 85.5% at layer 7.
  • Caltech-256: rising steadily from 24.6% at layer 1 to 71.7% at layer 7.

Broadly, the higher the layer, the better. On Caltech-101, layers 5 and 7 are close; on Caltech-256, accuracy keeps improving all the way to layer 7.

Conclusion

This paper used a deconvnet to project intermediate-layer activations back to pixels, then used those images to diagnose AlexNet. The first-layer aliasing and the dead filters were both spotted in the images first, and after the fixes, classification performance improved too. Here, visualization became a tool for adjusting the architecture.

In the ILSVRC 2013 classification challenge that same year, Zeiler and Fergus entered under the name “ZF” with a top-5 error of 13.5%, placing third; the winner was Clarifai, led by Zeiler, at 11.7% without extra data.

The visualization method itself was later put to the test. In 2014, Springenberg et al. combined the deconvnet with ordinary backpropagation into guided backpropagation in Striving for Simplicity. In 2018, Adebayo et al.'s Sanity Checks for Saliency Maps found that after the model's weights were randomized, the maps produced by guided backpropagation barely changed and looked a lot like plain edge detection. However clear a projection looks, you still need to check separately that it actually changes with the model.

Looking back at this paper, the effect of the architecture changes is backed by classification results. How faithful each projection really is was left for later research to answer.