VGG: repeated small-filter blocks
VGG
Trace VGG 16/19 configurations, compute receptive fields and parameter budgets, and run complete narrow versions.
vggStart with an experiment
Three small filters can inspect a region as wide as one large filter while using fewer weights under a stated channel assumption. They also place nonlinearities between the filters, changing what can be represented. VGG turns that observation into a regular design: repeat small convolutions, then reduce resolution, then repeat again.
The network is useful precisely because the pattern is easy to inspect. You can trace every spatial dimension and account for every parameter before allocating the model. The program below does that for the paper’s configurations D and E, and can execute either pattern at a much smaller width. The tiny forward pass has random weights; the architecture count is not a trained performance result.
The model and its assumptions
Simonyan and Zisserman’s inspected D/E configurations use 3-by-3 convolutions with stride one and padding one. Each block ends with 2-by-2 max pooling at stride two. Convolutional channel widths are 64,128,256,512,512; the fully connected head is 4096,4096,1000. Hidden layers use ReLU. Simonyan and Zisserman, 2015
| Configuration | Convolutions per block | Convolutions + fully connected layers |
|---|---|---|
| D | 2,2,3,3,3 | 13+3=16 |
| E | 2,2,4,4,4 | 16+3=19 |
The depth counts exclude pooling and activations. The paper also contains other configurations: C has 16 weighted layers but includes 1-by-1 convolutions. Stating D or E removes that ambiguity. For a 224-pixel input, the five pooling outputs have sides 112,56,28,14,7. D 2 L explains how a block can implement multiple convolutions before each downsampling step. Simonyan and Zisserman, 2015 D2L: VGG blocks
A chain’s theoretical receptive-field side r and spacing j between neighbouring outputs can be tracked from . For kernel size k and stride s, without dilation:
Thus two 3-by-3 stride-one layers have a 5-by-5 theoretical field; three have 7-by-7. This is a structural support bound, not a guarantee that every input pixel has equal or nonzero influence after weights and ReLU gates are considered.
Assume all input, intermediate and output widths equal C, and ignore biases. Three 3-by-3 layers use fewer weights than one 7-by-7 layer:
For two 3-by-3 layers versus one 5-by-5 layer, the corresponding counts are 18 C² and 25 C². Widening intermediate channels changes these comparisons. Equal receptive-field size does not imply equal functions: intervening ReLUs prevent a general replacement by one linear convolution.
For any one biased convolution and fully connected layer, count respectively:
At the full D configuration, the first fully connected layer takes inputs. It alone has 102764544 parameters. Large parameter memory therefore does not follow solely from the number of convolutional stages; the classifier head matters substantially.
A complete small program
Use Python 3.12 and NumPy 1.26.4. plan counts a full network without allocating its weights. tiny_vgg keeps the complete D or E layer pattern but uses 32-by-32 RGB input, widths 2/4/8/8/8, hidden width 16 and ten outputs. It performs genuine convolution, pooling, fully connected computation and softmax. Training, dropout masks and original pretrained initialization are not reproduced.
import numpy as np
REPEATS = {'D': (2,2,3,3,3), 'E': (2,2,4,4,4)}
def plan(configuration='D', side=224, channels=(64,128,256,512,512), hidden=4096, classes=1000):
if configuration not in REPEATS or type(side) is not int or side < 32:
raise ValueError('need configuration D/E and integer side >= 32')
if len(channels) != 5 or any(type(c) is not int or c < 1 for c in (*channels,hidden,classes)):
raise ValueError('need five positive integer widths, hidden size and class count')
n, incoming, layers = side, 3, []
for block,(repeats,outgoing) in enumerate(zip(REPEATS[configuration],channels),1):
for index in range(repeats):
weights = 9*incoming*outgoing
layers.append(dict(kind='conv', name=f'conv{block}_{index+1}', side=n,
incoming=incoming,outgoing=outgoing,
parameters=weights+outgoing, macs=n*n*weights))
incoming=outgoing
n//=2
layers.append(dict(kind='pool',name=f'pool{block}',side=n,channels=incoming,
parameters=0,macs=0))
incoming=n*n*incoming
for index,outgoing in enumerate((hidden,hidden,classes),1):
layers.append(dict(kind='fc',name=f'fc{index}',incoming=incoming,outgoing=outgoing,
parameters=incoming*outgoing+outgoing,macs=incoming*outgoing))
incoming=outgoing
return layers
def conv_same(image, weights, bias):
# HWC image; output-channel, input-channel, height, width weights.
a,w,b=np.asarray(image,dtype=float),np.asarray(weights,dtype=float),np.asarray(bias,dtype=float)
if a.ndim!=3 or w.ndim!=4 or w.shape[2:]!=(3,3) or w.shape[1]!=a.shape[2] or b.shape!=(w.shape[0],):
raise ValueError('need HWC image, OI33 weights and O bias')
if min(a.shape)<1 or w.shape[0]<1 or not all(np.isfinite(v).all() for v in (a,w,b)):
raise ValueError('arrays must be finite and nonempty')
padded=np.pad(a,((1,1),(1,1),(0,0)))
windows=np.lib.stride_tricks.sliding_window_view(padded,(3,3),axis=(0,1))
return np.einsum('hwcij,ocij->hwo',windows,w)+b
def max_pool(image):
a=np.asarray(image,dtype=float)
if a.ndim!=3 or min(a.shape[:2])<2 or a.shape[2]<1 or not np.isfinite(a).all():
raise ValueError('need finite HWC image with spatial dimensions >= 2')
h,w=a.shape[0]//2,a.shape[1]//2
return a[:2*h,:2*w].reshape(h,2,w,2,a.shape[2]).max(axis=(1,3))
def tiny_vgg(image, configuration='D', seed=17):
a=np.asarray(image,dtype=float)
if a.shape!=(32,32,3) or not np.isfinite(a).all():
raise ValueError('tiny demonstration expects finite 32x32 RGB values')
layers=plan(configuration,side=32,channels=(2,4,8,8,8),hidden=16,classes=10)
rng=np.random.default_rng(seed)
for layer in layers:
if layer['kind']=='conv':
incoming,outgoing=layer['incoming'],layer['outgoing']
weights=rng.normal(size=(outgoing,incoming,3,3))*np.sqrt(2/(9*incoming))
a=np.maximum(conv_same(a,weights,np.zeros(outgoing)),0)
elif layer['kind']=='pool':
a=max_pool(a)
else:
a=a.ravel()
weights=rng.normal(size=(layer['incoming'],layer['outgoing']))*np.sqrt(2/layer['incoming'])
a=a@weights
if layer['name']!='fc3':
a=np.maximum(a,0)
exponent=np.exp(a-a.max())
return exponent/exponent.sum()
if __name__=='__main__':
for configuration in ('D','E'):
layers=plan(configuration)
print(configuration,'weight layers:',sum(l['kind']!='pool' for l in layers),
'parameters:',sum(l['parameters'] for l in layers),
'multiply-accumulates:',sum(l['macs'] for l in layers))
image=np.random.default_rng(5).normal(size=(32,32,3))
p=tiny_vgg(image)
print('untrained tiny D probabilities:',p.round(5).tolist())
print('sum:',round(float(p.sum()),12))
D weight layers: 16 parameters: 138357544 multiply-accumulates: 15470264320
E weight layers: 19 parameters: 143667240 multiply-accumulates: 19632062464
untrained tiny D probabilities: [0.05428, 0.02933, 0.01649, 0.51783, 0.04502, 0.10334, 0.0211, 0.04703, 0.03642, 0.12918]
sum: 1.0
The exact totals are derived from the declared shapes and biases. The original table reports rounded millions, not all these digits. A multiply-accumulate is counted once here; bias additions, pooling comparisons and activations are excluded from the MAC total. A FLOP convention that counts multiplication and addition separately requires a different accounting. Simonyan and Zisserman, 2015
The checks cover D/E depth and dimensions, a literal multichannel convolution, odd-boundary pooling, both tiny networks, zero-input output, and invalid inputs. Impulse tests measure 3-by-3,5-by-5 and 7-by-7 support after one, two and three small convolutions. A separate counterexample confirms that removing an intermediate ReLU changes the function.
Runtime depends on each layer’s spatial size, channel widths and kernel, not just its position in the layer list. With fixed kernel size, doubling both input and output channels while halving both spatial dimensions leaves the leading convolution MAC count unchanged. That arithmetic does not imply identical latency or activation memory.
Limits and comparisons
Small kernels organize the design space; they do not make depth free. Training retains activations or recomputes them, parameter precision changes storage, and a wide fully connected head can dominate parameter memory. A larger theoretical receptive field also does not prove that a model uses context effectively.
The inspected paper’s training section reports batch size 256, momentum 0.9, weight decay 5×10⁻⁴ and dropout 0.5 in the first two fully connected layers. It describes initializing some deeper-network layers from configuration A and later notes that another random-initialization procedure also worked. These are reported experimental choices, not settings validated by the tiny forward example. We do not adopt the authors’ causal conjectures about convergence as proven explanations. Simonyan and Zisserman, 2015
A classifier intended for a different image size or label set needs an explicit head and preprocessing contract. Replacing the head with global pooling, inserting normalization or changing the block widths creates a variant that should be named and measured as such. Compare methods on the same data split and inference protocol, rather than treating a depth number as an accuracy ranking.
Exercises with answers
1. Why does configuration D count as 16 weighted layers?
Answer. Its five blocks contain 2+2+3+3+3=13 convolutions, followed by three fully connected layers. Pooling and ReLU are not included in this depth convention.
2. Compare three 3-by-3 kernels with one 7-by-7 kernel at constant width C.
Answer. They have the same theoretical 7-by-7 field at stride one without intervening pooling, but use 27 C² versus 49 C² weights excluding biases. Their nonlinear functions need not coincide.
3. Compute parameters in the first full-size fully connected layer.
Answer. Its 25088 inputs connect to 4096 outputs, each with a bias:25088×4096+4096=102764544.
4. Why can two ReLU-separated linear maps not always be merged?
Answer. Take input−1, first map+1 and second map−1. Applying ReLU between maps and after the second gives 0; multiplying the maps first and applying only the final ReLU gives 1.
Sources and next steps
The ICLR 2015 author paper supplies configurations, rationale and the scoped training account. Its tables were visually checked to avoid mixing columns during text extraction. D 2 L supplies the block-oriented teaching explanation; its broad priority claims are not required for the argument here. Simonyan and Zisserman, 2015 D2L: VGG blocks
Inception changes the block by introducing parallel spatial branches. ResNet changes the path through the block by adding a shortcut. Compare those changes with VGG’s explicit shapes and costs, not merely their names.
Make a prediction, then check
Configuration D has 13 convolutional layers. Why is it called 16 layers in the paper’s depth convention?
Learning objectives
- Reconstruct D/E depth, spatial shapes and exact parameter counts.
- Distinguish theoretical receptive field, nonlinear expressivity and computational cost.
Prerequisites & connections
Explore related knowledge →References
- Very Deep Convolutional Networks for Large-Scale Image Recognition — ICLR 2015 author paper
Karen Simonyan; Andrew Zisserman · 2015 - Dive into Deep Learning 1.0.3 — vgg
Aston Zhang; Zachary C. Lipton; Mu Li; Alexander J. Smola
Version1 · Editorial status: Recorded technical checks completed
View technical check record (AI)
Codex · 2026-09-07 · Codex single-AI-author technical check: bounded primary-source passages, explicit image classification experiments and CNN architecture models, executed programs, independent mathematical references, input boundaries and bilingual alignment. Not independent human or second-agent review; no full-system research reproduction claimed.
- Single-agent authored technical review; runnable example, exact or literal reference checks, explicit assumptions and matching bilingual equations/exercises. Automated execution and rendering results recorded separately.
- 8 tests: D/E depth, dimensions and exact parameter arithmetic; literal multichannel convolution; odd-boundary pooling; both tiny graphs;3/5/7 impulse support; nonlinear nonmergeability and invalid inputs. Corrected wording: the program can execute either tiny pattern, while its default main runs D.
- Single AI author compared both locales across six sections, assumptions, definitions, equations, executed code and output, four exercise/answer pairs and scoped citations.43 checks across six draft articles; not independent human review or full historical training reproduction.
- Complete bilingual prose and corresponding exercises promoted with formal status and SHA binding. Algorithm tests read formal MDX; historical essays claim no executable program or computational tests.
- After visual reading review, shortened/localized inline citation labels. Verified ordered link targets and every protected code/math/tag span unchanged; full source identities remain in metadata. Frozen drafts preserved and final article SHA rebound.
- Added the missing conjunction in the sentence describing the two supported tiny configurations; implementation scope unchanged.
Source locations checked:
- Very Deep Convolutional Networks for Large-Scale Image Recognition — ICLR 2015 author paper · ICLR2015 paper sections2.1/2.3, visually checked physical3 tables1/2, bounded physical4 training passage.
- Dive into Deep Learning 1.0.3 — vgg · Section8.2.1 VGG blocks and implementation; no upstream runtime or training reproduction.
Related topics