Neural Networks for Images
Convolutional Neural Networks — Architectures and other vision tasks
K. P. Murphy, Probabilistic Machine Learning: An Introduction — Chapter 14
2
Contents
14.1
Introduction
14.2
Common Layers
14.3
Architectures
14.4
Other Convolutions
14.5
Other Vision Tasks
3
14.1 Introduction
Recap — what does an MLP hidden layer compute?
Ch. 13: models for unstructured vectors x ∈ ℝᴰ
We can read wⱼ as a learned 'template' or pattern.
With ReLU, a good match yields a large activation → a signal that "pattern j is present in the input".
“Inner product = similarity measurement” — a CNN applies this inner product 'small, repeatedly, at every location'.
4
14.1 Introduction
Three reasons plain MLPs fail on images
problems that appear the moment the input is x ∈ ℝ^(W×H×C)
① Variable-sized input
If the image size changes, the weight matrix W must change too — a different model per size?
② Parameter
W has size (W×H×C)×D.
E.g. 224×224×3 input, 1024 hidden units
→ ~150 million parameters (one layer!)
③ No translation invariance
Weights are not shared across locations — a pattern learned on the left is not recognized on the right
5
14.1 Introduction
The CNN prescription — share a small filter across all locations
Murphy, PML Fig. 14.2 — classify a digit by discriminative part-templates in the right (relative) locations
A filter = a learned template for a 'part' of an object. Learned from data.
A 3×3×3 filter on a 224×224 input = just 27 parameters (independent of position).
The same response wherever the object sits — exactly what classification needs.
Filter size is independent of input size — only the output size changes.
8
14.2 Common Layers
1D discrete convolution and cross-correlation
Equation of 1d convolution:
Murphy, PML Fig. 14.3 — example of 1d discrete convolution
(Equation of 1d cross-correlation, Eq. 14.4)
Murphy, PML Fig. 14.4 — 1d cross-correlation
Identical when w is symmetric. In deep learning w is learned anyway, so the flip is irrelevant → by convention, cross-correlation is simply called convolution.
Same root as statistical correlation — at each position it measures 'how much x and w are similar'.
7
14.2 Common Layers
Why this operation?
Intuition ① — the distribution of a sum of two random variables IS a convolution
Sum over all pairs (u, z−u) whose total is z, multiplying probabilities — the g(z−u) in the definition is exactly this structure.
Intuition ② — Each output is inner product
Cross correlation can be interpreted as similarity score between x and w
9
14.2 Common Layers
Each output is 'filter · patch inner product' = a similarity score
Filter = template (direction), output = magnitude of that direction's component. A matched filter is the optimal linear detector of a signal in white noise.
The output map = a map of "how correlated is the local pixel arrangement here with the filter pattern?"
All-positive kernel = local mean (low-pass); mixed-sign kernel = local difference (high-pass, edges).
Cross-correlation spikes
when the pattern is present
(the matched-filter effect)
10
14.2 Common Layers
2D convolution
slide the filter W (H×W) over the image X in 2D (Eq. 14.5)
Murphy, PML Fig. 14.5 — example of 2d convolution
Murphy, PML Fig. 14.6 — response map of a diagonal-edge filter
Slide the window one step at a time: 3×3 input × 2×2 kernel → 2×2 output.
We can think of convolution as a form of feature detection. This is why Y = W⊛X is called a feature map.
11
14.2 Common Layers
Synthesis — why can kernel filters extract information from images?
three viewpoints, one conclusion
Signal processing
Matched filter: a filter shaped like the target pattern is the optimal linear detector (in white noise).
Output = an evidence map for the pattern's presence.
Statistics
Output ∝ correlation/covariance between filter and patch.
Natural-image statistics are stationary in position → sharing one filter across all locations is statistically justified.
Frequency
Convolution theorem: convolution in space = multiplication in frequency.
Filter = a selector of frequency/orientation components (edges = high-freq, blur = low-freq).
12
14.2 Common Layers
Convolution = matrix multiplication with special structure
Murphy, PML Eq. 14.8–14.9 — Toeplitz-like matrix C
Convolution is linear — a special case of matrix multiplication.
① Mostly zeros (sparse weight matrix)
② The same values w₁…w₄ repeat along diagonals (weight tying = sharing across positions)
Translation equivariance + a dramatic reduction in parameters.
13
14.2 Common Layers
Padding and stride
Murphy, PML Fig. 14.8 — (a) zero-padding same conv: 5×7 preserved (b) stride 2 → 3×4
Zero-padding adds a border of 0s; with 2p = f−1 you get same convolution.
p=padding size, f=filter size
14
14.2 Common Layers
Multiple input & output channels
C input channels → kernel W ∈ ℝ^(H×W×C×D) → D output channels (filters)
Murphy, PML Fig. 14.9 — 2-channel input: per-channel conv, then sum
Murphy, PML Fig. 14.10 — cylinders = hypercolumns
Stacking layers: the next layer template-matches the 'spatial arrangement of features' → the edge → texture → part → object hierarchy.
15
14.2 Common Layers
1×1 (pointwise) convolution and pooling
Murphy, PML Fig. 14.11 — 1×1×3×2: 3 channels → 2
Murphy, PML Fig. 14.12 — 2×2 max pooling
Uses: channel reduction/expansion (bottleneck), feature recombination
Keep only the max(or average, mean, etc…) in the window → output unchanged under small shifts.
For classification, we can apply classifier to an any size of image, because GAP will always converts feature map to fixed D-dimension feature.
16
14.2 Common Layers
Assembling the parts — the classic CNN design pattern
[Conv + ReLU → Pool] repeated → Flatten → FC → Softmax
Murphy, PML Fig. 14.13 — feature-learning stage + classification stage
17
14.2 Common Layers
Normalization layers-proposed to mitigate internal covariate shift
Batch Normalization
Internal layer distributions keep shifting during training (internal covariate shift) → recompute per batch.
Murphy, PML Fig. 14.14 — blue region = normalized by the different (μ,σ)
Replace activation vector, or pre-activation vector
18
14.3 Architectures
LeNet (1998) — the prototype of the modern CNN
Murphy, PML Fig. 14.15 — LeNet5
Murphy, PML Fig. 14.17 — predictions after 1 epoch (red = wrong)
Alternating conv-pool + final FC classifier — exactly the design pattern from 14.2.
A quantitative demonstration of the gains from convolution's inductive bias.
19
14.3 Architectures
AlexNet (2012) — the trigger of the deep-learning boom
Murphy, PML Fig. 14.16 — (a) LeNet5 vs (b) AlexNet
① deeper (5 → 8 trainable layers) ② tanh → ReLU ③ weight decay → dropout ④ conv layers stacked back-to-back (no strict conv-pool alternation)
Three 3×3s = a 7×7 receptive field, but fewer parameters
Mostly in the 3 final FC layers. Trained split across 2 GPUs
The idea (CNNs) existed in 1998 — what was missing was data (ImageNet), compute (GPUs), and a few training tricks
20
14.3 Architectures
GoogLeNet / Inception (2014) — don't choose a filter size, use them all
Murphy, PML Fig. 14.18 — Inception module
Murphy, PML Fig. 14.19 — full model (9 inception blocks + GAP)
The model itself learns, per layer, which scale of feature is useful.
The bottleneck controls the compute cost of going parallel
Removes AlexNet's FC parameter bomb → a much lighter model.
21
14.3 Architectures
ResNet (2015) — introducing residual block
Murphy, PML Fig. 14.20 — residual block (right: 1×1 conv to match channels)
Gradients flow directly from the output to early layers → very deep training becomes possible.
Murphy, PML Fig. 14.21 — ResNet-18: (Conv:BN:Max):(R:R):(R′:R)×3:Avg:FC — input reduced 2⁵=32× before GAP
22
14.3 Architectures
DenseNet (2017) — concatenate, don't add
every layer receives the outputs of ALL previous layers directly
Murphy, PML Fig. 14.22 — (a) add vs concat, (b) dense connectivity
Instead of add earlier features, concatenate them so later layers can use them directly.
All previously computed features are directly accessible to the output layer.
Mitigated by interleaved 1×1 conv layers and stride-2 pooling.
23
14.3 Architectures
Neural Architecture Search — learning the design itself
the networks so far = different arrangements of the same blocks → search that arrangement automatically
ConvNeXt (2022) is a SOTA CNN built by stacking small refinements on a standard ResNet
Can optimize multiple objectives — accuracy plus model size and inference speed — this is how EfficientNetv2 was created.
24
14.4 Other Convolutions
Transposed convolution — from a small input to a larger output
'stencil stamping': the kernel is the stamp, the input value is the ink intensity
Murphy, PML Fig. 14.24 — 2×2 input × 2×2 kernel → 3×3 output
Murphy, PML Fig. 14.25 — terminology warning: NOT deconvolution (the inverse problem of undoing a known filter)!
25
14.4 Other Convolutions
Depthwise separable convolution — separate space from channels
split standard conv (H×W×C×D) into two steps to cut cost (the core of MobileNet & edge models)
Murphy, PML Fig. 14.26 — per-channel 2D conv → 1×1 conv combines channels
Standard: 5·5·3·256 = 19,200 parameters
Separable: 5·5·3 + 1·1·3·256 = 843 parameters (≈23× fewer; output still 8×8×256)
26
14.5 Other Vision Tasks
Image tagging — multiple labels per image
classification (mutually exclusive single label) → multi-label prediction
Just replace the final softmax with C independent logistic (sigmoid) units.
Noisy (many tags aren't visually well defined), but useful for pre-training.
Real images contain multiple objects — which one should be 'the' label? Karpathy's human-benchmark analysis on ImageNet: 16% of human errors come from 'multiple objects but only one correct label'.
27
14.5 Other Vision Tasks
Object detection — what, where, and however many
variable-count outputs: closing an open world with anchor boxes
Murphy, PML Fig. 14.27 — (a) face detection (b) anchor boxes
For each box, predict ① object presence probability ② class ③ box offsets (position refinement).
Many variants trading off speed, accuracy, simplicity.
(distinct from face recognition — identifying who it is)
30
14.5 Other Vision Tasks
Human pose estimation — finding skeletal keypoints
predict the locations of a fixed set of keypoints: head, hands, joints …
Murphy, PML Fig. 14.32 — OpenPose: body, hand, and face keypoints
Representative systems: PersonLab, OpenPose — real-time, multi-person.
The hard part is 3D labels — humans struggle to annotate in 3D → use graphics engines to synthesize data with unlimited ground truth.
Action recognition, AR/VR, sports analytics, human-robot interaction.
31
Summary
1
Each convolution output = the inner product of the filter with a local patch = a similarity (correlation) score
Why kernel filters extract image information
2
A CNN = a sparse, tied MLP with locality and weight sharing hard-coded
3
The history of architectures = the history of improving gradient flow and parameter efficiency
LeNet → AlexNet (depth·ReLU) → Inception (parallel) → ResNet (residual) → DenseNet (connectivity) → NAS (automation).
References: K. P. Murphy, Probabilistic Machine Learning: An Introduction, Ch. 14 (probml.github.io) · 3Blue1Brown, “But what is a convolution?” (youtube.com/watch?v=KuXjwB4LzSA)