ZFNet (Zeiler and Fergus, 2014) is AlexNet with a smaller, finer first layer (7 × 7 kernels at stride 2 instead of 11 × 11 at stride 4), a change found by looking inside the network. Its lasting contribution is the tools it used: a deconvolutional network that projects any feature back to pixel space, and occlusion experiments that show which parts of an image a prediction depends on. This page covers the architecture change, the deconvnet (unpooling with switches, rectification, transposed filters) and what the visualisations revealed. In the exercises you implement unpooling with switches, then run the occlusion test on a small CNN: the most damaging 3 × 3 patch lay on the digit in 99–100% of images (70% by chance), and covering the digit cut confidence about 30 times more than covering background.
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.
Looking inside the black box
After AlexNet, nobody quite knew what its neurons had learned. Matthew Zeiler and Rob Fergus built tools to find out. For any neuron they could draw the parts of an image that excited it, and they could cover parts of an image to see which parts the answer depended on. The pictures showed that AlexNet’s first layer had dead filters and blocky artefacts. Shrinking its first-layer kernels and stride fixed that and improved accuracy: the improved network is ZFNet.
Architecture explorer: shapes, parameters and compute
stage
output C × H × W
parameters
multiply–adds
conv1
96 × 55 × 55
14.2 k
170.76 M
conv2
256 × 13 × 13
614.7 k
415.33 M
conv3-5
256 × 6 × 6
3.10 M
523.32 M
fc6-8
1000 × 1 × 1
58.63 M
58.62 M
Total: 62,357,608 parameters (62.36 M), 1.17 G multiply–adds per image at 224 × 224.
AlexNet
61.10 M parameters
714.19 M MACs
ZFNet
62.36 M parameters
1.17 G MACs
Bars show each row's share of the total. Convolutions dominate compute because they run at every position; fully connected layers dominate parameters in older designs (AlexNet, VGG). Changing the input size changes the compute of every convolution but not its parameters. Parameter counts include biases and BatchNorm scale and shift and match torchvision's implementations.
Why engineers care
Before trusting a vision network on a robot or satellite, engineers need evidence that it looks at the object and not at the background. Occlusion tests give that evidence without access to the network’s internals.
📝 Quick check (Level 0)
0/3 answered
1. ZFNet changed AlexNet's…
2. Occlusion tests cover parts of an image to see…
3. The deconvnet shows…
Level 1: Beginner
★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.
By hand
First layer: AlexNet uses 11 × 11 kernels at stride 4 (224 → 55). ZFNet uses 7 × 7 at stride 2 with padding 1, giving (224 + 2 − 7)/2 + 1 = 110.
Next stages: pooling 3/2 gives 55; conv2 (5 × 5, stride 2) gives 26; pooling gives 13; three 3 × 3 convolutions keep 13; a final pooling gives 6. Then come fully connected layers of 4,096, 4,096 and 1,000 units.
Parameters: about 62.4 million, almost all in the fully connected layers. Compute is about 1.17 G multiply–adds, against 0.71 G for AlexNet, because the first layers run at higher resolution.
Unpooling with switches: pooling [[1, 5], [3, 4]] gives 5, with switch (0, 1). Unpooling puts 5 back at (0, 1) and zeros elsewhere.
Occlusion positions: a 3 × 3 patch slid over a 10 × 10 image has 8 × 8 = 64 positions.
📝 Quick check (Level 1)
0/3 answered
1. ZFNet's conv1 output side for 224 × 224:
2. A switch records…
3. Occluder positions for 3 × 3 on 10 × 10:
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.
Visualising in code
Exercise 1.
Max pooling with switches returned [[5, 8], [9, 3]] for the 4 × 4 example.
Unpooling placed each maximum back at its source and zeros elsewhere.
ZFNet’s first layer produced 110 × 110 maps against AlexNet’s 55 × 55.
Practice.
The deconvnet visualises a feature by setting all other activations in its layer to zero and passing the map back through three steps:
unpooling with the recorded switches;
ReLU;
convolution with the transposed (flipped) filters.
Today the same idea is usually done with gradients:
guided backpropagation (Springenberg et al., 2015) is a close relative;
Grad-CAM (Selvaraju et al., 2017) weights the last convolutional maps by their average gradient.
Occlusion needs only forward passes:
slide a grey or mean-valued patch;
record the drop in the true-class probability;
plot it as a heat map.
heat = np.zeros((m, m))for a in range(m): for b in range(m): x = img.clone(); x[:, a*s:a*s+k, b*s:b*s+k] = mean heat[a, b] = p_true(img) - p_true(x)
🐍 Exercise 1: unpooling with switches
Max-pool with switches, unpool, and compare ZFNet's and AlexNet's first layers.
📝 Quick check (Level 2)
0/3 answered
1. The deconvnet passes a map back through…
2. Occlusion maps need…
3. Grad-CAM weights the last conv maps by…
Level 3: Advanced
★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.
Theory
What the visualisations showed.
Hierarchy of features:
layers 1 and 2 respond to edges, colours and corners;
layer 3 to textures and meshes;
layers 4 and 5 to object parts and whole objects, such as dog faces and wheels.
Training dynamics: lower layers converged within a few epochs; upper layers developed only after 40 to 50 epochs.
Invariance: small translations and scalings changed layer-1 features a lot but the top layers little; rotation invariance was weak except for rotationally symmetric objects.
Why the first layer changed. With 11 × 11 kernels at stride 4, AlexNet’s first-layer filters mixed very high and very low frequencies with few mid-frequency filters, and some filters were dead. Its second-layer features also showed aliasing from the large stride. A 7 × 7 kernel at stride 2 kept more information and gave cleaner features and better accuracy.
What occlusion measures. The drop in the true-class probability when a region is masked estimates how much the prediction depends on that region. The method has two limits:
it measures the effect of a particular masking value, so a mask that looks unnatural can itself change the prediction;
it cannot detect redundant evidence, because masking one of two sufficient cues leaves the prediction unchanged.
📝 Quick check (Level 3)
0/3 answered
1. Layers 4–5 respond to…
2. Upper layers converged after about…
3. Occlusion misses…
Level 4: Expert
★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.
Does the network look at the digit?
History.
M. Zeiler, G. Taylor, R. Fergus (2011) introduced deconvolutional networks.
M. Zeiler and R. Fergus (2014) used them to visualise and improve AlexNet. Their ensemble reached 14.8% top-5 error on ImageNet 2012, and Clarifai, Zeiler’s company, won the ILSVRC 2013 classification task with 11.7%.
They also showed ImageNet features transfer: retraining only the classifier on Caltech-101 and Caltech-256 beat the previous best results.
Exercise 2. A small convolutional network (as in E8-1) is trained on 300 shifted digits. For each of 300 test digits classified confidently (true-class probability above 0.5), a 3 × 3 patch set to 0 is slid over every position, and the drop in the true-class probability is recorded.
seed
confidently classified
most damaging patch on the digit
chance
mean drop, patch on digit
off digit
0
0.573
1.000
0.709
0.232
0.0065
1
0.590
0.994
0.701
0.298
0.0094
The network depends on the digit, not the background. The single most damaging patch overlapped the digit in nearly every image, where chance would give about 70%. The 7 × 5 box covers much of the 10 × 10 canvas, so chance is high, and the hit rate is the stronger test.
Covering the digit cut confidence about 30 times more than covering background. Seeds 2 to 4 gave hit rates of 0.99 to 1.00.
This test cannot tell which strokes matter, or whether the network would still be right using a different part of the digit. Those questions need finer occluders or gradient-based maps.
🐍 Exercise 2 (research): does the network look at the digit?
Train a small CNN, slide an occluder over test digits, and measure whether the confidence drop is concentrated on the digit.
Visualisation in AI, robotics and aerospace
Certification: occlusion and saliency maps are used to argue that perception networks for driving and aviation attend to relevant features, though they are evidence, not proof.
Debugging datasets: occlusion often reveals shortcuts, such as a network recognising a class by a watermark or by the background sky, before deployment.
Remote sensing: saliency maps check that land-cover classifiers use the land, not clouds or image borders.
References
M. D. Zeiler, R. Fergus (2014). “Visualizing and understanding convolutional networks.” Proc. ECCV.
M. D. Zeiler, G. W. Taylor, R. Fergus (2011). “Adaptive deconvolutional networks for mid and high level feature learning.” Proc. ICCV.
J. T. Springenberg, A. Dosovitskiy, T. Brox, M. Riedmiller (2015). “Striving for simplicity: the all convolutional net.” ICLR workshop.
R. R. Selvaraju et al. (2017). “Grad-CAM: visual explanations from deep networks via gradient-based localization.” Proc. ICCV.
The most damaging occluder fell on the digit in 99–100% of images.
Practice
Show:
Level 0
Problem 1Level 0
Kernel size of ZFNet’s first layer?
7 (7 × 7).
Problem 2Level 0
Stride of ZFNet’s first layer?
2.
Problem 3Level 0
Positions of a 3 × 3 occluder on a 10 × 10 image (stride 1)?
8² = 64.
Level 1
Problem 4Level 1
ZFNet’s conv1 output side for a 224 × 224 input?
(224 + 2 − 7)/2 + 1 = 110.
Problem 5Level 1
conv2 output side (5 × 5, stride 2, no padding) from 55?
(55 − 5)/2 + 1 = 26.
Problem 6Level 1
Parameters of ZFNet’s conv1 (7 × 7, 3 → 96, with bias)?
49·3·96 + 96 = 14208.
Problem 7Level 1
Positions of a 50 × 50 occluder slid with stride 8 over 224 × 224?
((224 − 50)/8 + 1)² = 22² = 484.
Level 2
Problem 8Level 2
Hit rate of the most damaging patch for seed 0 in exercise 2?
1.000.
Problem 9Level 2
Chance hit rate for seed 0?
0.709.
Problem 10Level 2
Mean confidence drop with the patch on the digit, seed 1?
0.298.
Problem 11Level 2
Ratio of on-digit to off-digit mean drop for seed 0, to the nearest whole number?
0.232/0.0065 ≈ 36.
Problem 12Level 2
Fraction of test digits classified confidently, seed 0?
0.573.
Problem 13Level 2
Ratio of ZFNet’s to AlexNet’s multiply–adds, using 1.17 G and 0.71 G?
1.17/0.71 ≈ 1.65.
Level 3
Problem 14Level 3
Show that unpooling with switches followed by pooling recovers the pooled values exactly.
Unpooling puts each pooled value v at its switch position inside its window and zeros elsewhere. Pooling that window again takes the maximum. If v ≥ 0, the maximum is v. Pooled values can be negative only if a whole window was negative; then the zeros win, so exact recovery needs v ≥ 0, which holds after ReLU. Both steps use the same windows, so the map is recovered value by value. ∎
Problem 15Level 3
Explain why the chance hit rate in exercise 2 is as high as 70%.
A 3 × 3 occluder overlaps the 7 × 5 glyph box whenever their row ranges and column ranges intersect. Its top-left corner can be at any of 8 × 8 positions; for a box at a typical place, overlapping positions span up to 9 rows and 7 columns of corners, which is most of the 64. So a random patch overlaps the digit about 70% of the time. That is why the near-perfect hit rate is meaningful, and why the drop ratio is the stronger evidence. ∎
Problem 16Level 3
Explain why ZFNet’s first-layer change increased compute although it kept the same number of channels.
Compute is output positions × kernel size × channels. Halving the stride from 4 to 2 quadruples the positions (110² against 55²), while the kernel shrinks from 121 to 49 pixels. The first layer’s cost rises by about 4·49/121 ≈ 1.6 times. The larger maps also feed later layers: conv2 runs at 26² instead of 27² positions but on finer features. The total rose from 0.71 G to 1.17 G multiply–adds. ∎
Problem 17Level 3
Advise how to check that a runway-detection network on an aircraft attends to the runway.
Run occlusion maps on held-out approach images, with the mask set to a plausible value such as a local blur, and measure the fraction of top-sensitivity regions inside labelled runway polygons against chance. Also check Grad-CAM maps, test images where context changes (night, snow, different airports), and synthetic edits that move or remove the runway. Report quantitative overlap, not just example pictures. ∎
Level 4
Problem 18Level 4
Zeiler and Fergus’s ensemble top-5 error on ImageNet 2012, in percent?
14.8.
Problem 19Level 4
Hit rate for seed 1 in exercise 2?
0.994.
Problem 20Level 4
Factor by which halving the stride multiplies the number of output positions?
2² = 4.
Coding practice
🐍 Code 1 (Level 1): output size
⌊(n + 2p − k)/s⌋ + 1.
🐍 Code 2 (Level 0): occlude
Copy the image and set a k × k patch to a value.
🐍 Code 3 (Level 1): occluder positions
((n − k)//stride + 1)².
🐍 Code 4 (Level 1): max with switch
Value and position of a block's maximum.
🐍 Code 5 (Level 1): overlap test
Does a k × k patch overlap an h × w box?
Topic test
A timed test drawn at random from this topic's question bank. Each attempt gets new questions. For a longer test across the whole chapter, see the chapter test, or mix topics in the question bag.
ZFNet: topic test
10 questions, drawn at random from a bank of 21. Every attempt is different.
⏱ Time limit: 15 minutes. The test submits itself when time runs out.
Levels covered: 0, 1, 2, 3, 4. No hints or solutions until you submit.