1.7 Convolutional neural networks (CNN)

1MEC102 · Module 1: AI Ecosystem and Intelligent Computing

How CNNs see: local receptive fields, shared filters, padding, stride, pooling and the classic architectures, with solved numericals for ECE applications.

Lesson at a glance

Time 60 minutes of class + 45 minutes of self-study
Prerequisites 1.5 The perceptron, 1.6 ANNs and backpropagation
Course outcomes CO2 (analyse and evaluate learning algorithms), CO3 (design AI models for vision and embedded applications)
Textbook Géron, Hands-On Machine Learning, 3rd ed., Ch. 14 “Deep Computer Vision Using CNNs”; Goodfellow et al., Deep Learning, Ch. 9

Learning outcomes

By the end of this lesson you will be able to:

  1. Explain why fully connected networks are a poor fit for images, using parameter counts. L2
  2. Compute a 2-D convolution, the output size for any padding and stride, and the result of max or average pooling by hand. L3
  3. Calculate the parameters, multiplications and activation memory of a convolutional layer. L3
  4. Trace the tensor shapes through a complete CNN such as LeNet-5. L4
  5. Evaluate whether a CNN design fits the flash, RAM and speed budget of an embedded device. L5

The big picture: an analogy

Analogy: the PCB inspector with a magnifying loupe

Picture a quality inspector checking a large printed circuit board. She does not take in the whole board at once. She slides a small loupe across it, square by square, asking the same checklist at every position: “Is there a solder bridge here? A broken trace? A missing component?”

  • The loupe is the kernel (filter): it sees only a small patch, its receptive field.
  • Using the same checklist everywhere is weight sharing: one set of weights, applied at every position.
  • Each checklist item is a different filter, and the marks she makes on a copy of the board for that item form a feature map.
  • After the close inspection she steps back and summarises each region (“this corner has a bridge somewhere”). That is pooling.
  • A senior engineer reads her summaries and decides “reject: solder bridge near U7”. That is the dense classifier at the end.

A CNN is this inspector, except that it learns its own checklist from labelled examples.

The idea comes from biology. Hubel and Wiesel showed in the late 1950s and 1960s that neurons in the visual cortex respond only to stimuli in a small region of the visual field, and that some respond to edges at particular orientations. Higher-level neurons combine the outputs of lower-level ones to detect more complex patterns. LeCun and colleagues turned this into a trainable architecture, LeNet-5, which read handwritten digits on bank cheques (LeCun et al., 1998).

1. Why not just use a fully connected network?

A dense (fully connected) layer connects every input to every neuron. For images this explodes quickly:

Input image Values in the input Weights for a first dense layer of 1,000 neurons
28 × 28 grey (MNIST) 784 ≈ 0.78 million
224 × 224 RGB 150,528 ≈ 150 million
1024 × 1024 grey (wafer inspection) 1,048,576 ≈ 1 billion

Two further problems:

  • No spatial sense. Flattening throws away which pixels are neighbours, so the network must re-learn that a vertical edge is a vertical edge at every position.
  • No translation invariance. A defect detected in the top-left corner teaches the network nothing about the same defect in the bottom-right.

CNNs fix all three problems with two ideas: local connectivity (each neuron sees a small patch) and weight sharing (the same filter is used everywhere).

2. The convolution operation

A filter (kernel) \(\mathbf{K}\) of size \(f_h \times f_w\) slides over the input. At each position it multiplies element by element with the patch under it and adds up the products, plus a bias \(b\):

\[ z_{i,j} = b + \sum_{u=0}^{f_h-1} \sum_{v=0}^{f_w-1} x_{\,i\cdot s+u,\; j\cdot s+v}\; w_{u,v} \]

where \(s\) is the stride. With several input channels (for example R, G and B) the filter has the same depth as the input and the sum also runs over the channels \(k'\):

\[ z_{i,j,k} = b_k + \sum_{u}\sum_{v}\sum_{k'} x_{\,i\cdot s+u,\; j\cdot s+v,\; k'}\; w_{u,v,k',k} \]

Each filter \(k\) produces one feature map; a layer with 64 filters produces 64 feature maps stacked into a 3-D output.

Figure 1: Convolution by hand: the 3 × 3 vertical-edge kernel over columns 1–3 of the input gives (10+10+10) − (0+0+0) = 30. The output is non-zero only where the image changes from bright to dark.
Note for ECE students: convolution or correlation?

In signals and systems, convolution flips the kernel: \(y[n]=\sum_k x[k]\,h[n-k]\). Deep-learning libraries do not flip it; they compute cross-correlation. Because the kernel is learned, the difference does not matter in practice (the network simply learns the flipped kernel), but be careful when you compare a CNN filter with a filter designed by hand in MATLAB.

What do learned filters look like?

Early layers learn small, simple detectors: edges at different orientations, colour blobs, simple textures. Figure 2 shows two hand-made edge filters applied to a synthetic image of PCB traces. Each filter responds to only one kind of edge. A trained CNN learns dozens of such filters in its first layer, then combines them in deeper layers into corners, pads, vias and finally whole defect patterns.

Figure 2: Feature maps from a synthetic PCB image. The kernel [1, 0, −1] responds to edges where the image goes from bright to dark, left to right; the opposite edge gives negative values that ReLU removes. Max pooling halves the size but keeps the strongest responses.

3. Padding and stride

Zero padding adds rows and columns of zeros around the input, so the filter can be centred on border pixels and the output keeps its size. Stride \(S\) is the step between successive positions of the filter; \(S=2\) roughly halves the output.

\[ O = \left\lfloor \frac{N + 2P - F}{S} \right\rfloor + 1 \]

Keras setting Meaning Output size
padding="valid" No padding (\(P=0\)); edge pixels that don’t fit a full window are ignored \(\lfloor (N-F)/S \rfloor + 1\)
padding="same" Pad just enough that the output is \(\lceil N/S \rceil\) \(\lceil N/S \rceil\)

4. Parameters, computation and memory

A filter has \(f_h \cdot f_w \cdot C_\text{in}\) weights plus one bias, and a layer has \(C_\text{out}\) filters:

\[ \text{Parameters} = (f_h f_w C_\text{in} + 1)\, C_\text{out} \]

Weight sharing makes this tiny compared with a dense layer, but the computation and activation memory can be large, because every filter is applied at every output position:

\[ \text{MACs} = O_h\,O_w\,C_\text{out}\,(f_h f_w C_\text{in}), \qquad \text{Activation memory} = O_h\,O_w\,C_\text{out} \times \text{bytes per value} \]

This trade-off (few parameters, heavy compute and RAM) is the central design constraint when a CNN must run on a microcontroller, where RAM is often only 2–512 KB and flash 32 KB–2 MB (Brockmann et al., 2024).

5. Activation and pooling

After each convolution a non-linearity, usually ReLU \(=\max(0,z)\), is applied element-wise. Without it, stacked convolutions would collapse into a single linear filter.

A pooling layer shrinks each feature map. It has no learnable parameters:

  • Max pooling keeps the largest value in each window (the strongest evidence that the feature is present).
  • Average pooling keeps the mean.
  • Global average pooling averages each whole feature map to one number; modern CNNs use it before the classifier instead of a large Flatten + Dense.

A 2 × 2 pool with stride 2 removes 75% of the values, reduces later computation, and makes the network tolerant of small shifts.

6. Putting it together: a complete CNN

Figure 3: A typical CNN for 64 × 64 wafer maps. Spatial size shrinks while depth (number of feature maps) grows; the dense layers at the end make the decision.

The receptive field grows with depth: two stacked 3 × 3 convolutions see a 5 × 5 region of the input, three see 7 × 7. In general \(L\) stacked \(F \times F\) layers with stride 1 see \(L(F-1)+1\) pixels, which is why modern networks prefer stacks of small kernels.

from tensorflow import keras
model = keras.Sequential([
    keras.layers.Input(shape=(64, 64, 1)),
    keras.layers.Conv2D(32, 3, padding="same", activation="relu"),
    keras.layers.MaxPooling2D(2),
    keras.layers.Conv2D(64, 3, padding="same", activation="relu"),
    keras.layers.MaxPooling2D(2),
    keras.layers.Flatten(),
    keras.layers.Dense(128, activation="relu"),
    keras.layers.Dense(8, activation="softmax"),
])
model.summary()   # 320 + 18,496 + 2,097,280 + 1,032 = 2,117,128 parameters

7. Landmark architectures

Network Year Key idea to remember
LeNet-5 1998 Conv + average pooling + tanh; read handwritten digits on cheques
AlexNet 2012 Deeper stack trained on GPUs; ReLU, dropout and data augmentation; won ImageNet by a wide margin
VGG 2014 Only 3 × 3 kernels, stacked deep
GoogLeNet 2014 Inception modules with 1 × 1 “bottleneck” convolutions; far fewer parameters
ResNet 2015 Skip connections let very deep networks (50–152 layers) train; covered in Module 3
MobileNet / EfficientNet 2017–19 Depthwise-separable convolutions and compound scaling for phones and embedded devices; covered in Modules 3 and 4

8. CNNs in electronics engineering

  • Wafer-map defect classification. A CNN trained only on synthetic wafer maps classified 22 defect classes with 98.2% test accuracy and transferred to real wafers (Nakazawa and Kulkarni, 2018). On the public WM-811K dataset, data augmentation against class imbalance raised average accuracy to 96.2% (Saqlain et al., 2020), and a MobileNetV3 classifier matched ResNet’s accuracy with 7.5 times fewer parameters and 4.9 times faster inference (Shin et al., 2023).
  • Automated optical inspection (AOI) of PCBs and solder joints.
  • Spectrogram classification for audio, vibration and radar signals: a 1-D signal becomes a 2-D time–frequency image that a CNN can read.
  • TinyML vision on microcontrollers, such as person detection or meter reading, using frameworks such as TensorFlow Lite Micro (David et al., 2020); see the review by Lin et al., 2023.

9. Solved numericals

Formulas you need

\(O=\lfloor (N+2P-F)/S \rfloor + 1\) · \(O_\text{same}=\lceil N/S\rceil\) · Params \(=(f_hf_wC_\text{in}+1)C_\text{out}\) · MACs \(=O_hO_wC_\text{out}f_hf_wC_\text{in}\) · Memory \(=O_hO_wC_\text{out}\times\) bytes · Receptive field \(=L(F-1)+1\)

N1. Convolution by hand L3

Apply \(K=\begin{bmatrix}1&0&-1\\1&0&-1\\1&0&-1\end{bmatrix}\) to the 5 × 5 image \(I\) whose first three columns are 10 and last two are 0 (Figure 1), with stride 1 and no padding.

  1. Output size: \(O=(5-3)/1+1=3\), so the output is 3 × 3.
  2. Position (0,0) covers columns 0–2, all 10s: \((10+10+10)(1)+0+(10+10+10)(-1)=0\).
  3. Position (0,1) covers columns 1–3: left column sum 30, right column sum 0, so \(30-0=30\).
  4. Position (0,2) covers columns 2–4: left column 30, right column 0, so 30.
  5. All rows of the image are identical, so all output rows are identical.

\(O=\begin{bmatrix}0&30&30\\0&30&30\\0&30&30\end{bmatrix}\): the filter fires only at the vertical bright-to-dark edge.

N2. Output sizes with padding and stride L3

Find the output width for (a) \(N=32,F=5,S=1,P=0\); (b) \(N=227,F=11,S=4,P=0\) (AlexNet’s first layer); (c) \(N=224,F=7,S=2,P=3\) (ResNet’s first layer); (d) \(N=13,F=6,S=5\) with “valid” and “same” padding.

    1. \((32-5)/1+1=28\).
    1. \((227-11)/4+1=54+1=55\).
    1. \(\lfloor(224+6-7)/2\rfloor+1=\lfloor111.5\rfloor+1=112\).
    1. Valid: \(\lfloor(13-6)/5\rfloor+1=2\); the last 3 input columns are never used. Same: \(\lceil13/5\rceil=3\); to fit three windows the padded width must be \((3-1)\cdot5+6=16\), so 3 zeros are added (1 left, 2 right).
  1. 28 · (b) 55 · (c) 112 · (d) valid 2, same 3

N3. Parameters, computation and memory of a convolutional layer L3

A layer applies 64 filters of 3 × 3 to a 224 × 224 × 3 image, stride 1, “same” padding, 32-bit floats. Find (a) parameters, (b) multiplications per image, (c) output memory per image and per batch of 32, (d) parameters of a dense layer of 64 neurons on the flattened image.

  1. Parameters: \((3\cdot3\cdot3+1)\cdot64=28\cdot64=1{,}792\).
  2. Output is 224 × 224 × 64; each value needs \(3\cdot3\cdot3=27\) MACs: \(224\cdot224\cdot64\cdot27=86{,}704{,}128\approx86.7\) M.
  3. Memory: \(224\cdot224\cdot64=3{,}211{,}264\) values × 4 B \(=12.8\) MB per image, ≈ 411 MB per batch of 32 (kept for the backward pass during training).
  4. Dense: \(150{,}528\cdot64+64=9{,}633{,}856\) parameters.

1,792 parameters (about 5,400 times fewer than the dense layer’s 9.63 M), but 86.7 M MACs and 12.8 MB of activations per image.

N4. Max and average pooling L3

Apply 2 × 2 pooling with stride 2 to \(\begin{bmatrix}1&3&2&4\\5&6&1&2\\7&2&9&0\\1&8&3&4\end{bmatrix}\).

  1. Windows: top-left {1,3,5,6}, top-right {2,4,1,2}, bottom-left {7,2,1,8}, bottom-right {9,0,3,4}.
  2. Max: 6, 4, 8, 9.
  3. Mean: 15/4 = 3.75, 9/4 = 2.25, 18/4 = 4.5, 16/4 = 4.0.

Max \(\begin{bmatrix}6&4\\8&9\end{bmatrix}\), average \(\begin{bmatrix}3.75&2.25\\4.5&4.0\end{bmatrix}\); no parameters are learned.

N5. Trace LeNet-5 L4

Trace the shapes and count the parameters of LeNet-5, assuming full connections between feature maps and a 10-neuron dense output.

Layer Operation Output Parameters
In 32 × 32 input 32 × 32 × 1 0
C1 6 conv 5 × 5 28 × 28 × 6 \((25+1)\cdot6=156\)
S2 avg pool 2 × 2 14 × 14 × 6 12 (one coefficient + bias per map)
C3 16 conv 5 × 5 10 × 10 × 16 \((25\cdot6+1)\cdot16=2{,}416\)
S4 avg pool 2 × 2 5 × 5 × 16 32
C5 120 conv 5 × 5 1 × 1 × 120 \((25\cdot16+1)\cdot120=48{,}120\)
F6 dense 84 84 \(120\cdot84+84=10{,}164\)
Out dense 10 10 \(84\cdot10+10=850\)

The original LeNet-5 connected C3 to only some S2 maps (1,516 parameters) and used an RBF output layer.

About 61,750 parameters, fewer than a quarter of a 784-300-100-10 MLP (266,610).

N6. HOTS: will it fit on the microcontroller? L4 L5

An inspection camera produces 128 × 128 grey images of solder joints in 4 classes. The MCU has 512 KB flash, 256 KB RAM (int8 weights and activations) and runs about 100 M MACs/s; the line needs 5 images/s. Design Q is Conv(16, 3 × 3, same) → MaxPool 2 → Conv(32, 3 × 3, same) → MaxPool 2 → Conv(64, 3 × 3, same) → Global average pooling → Dense(4). Evaluate whether it fits, and fix it if not.

  1. Parameters: Conv1 \((9+1)\cdot16=160\); Conv2 \((144+1)\cdot32=4{,}640\); Conv3 \((288+1)\cdot64=18{,}496\); Dense \(64\cdot4+4=260\); total 23,556 ≈ 23.6 KB. Flash: fits.
  2. Peak RAM at Conv1: input \(128\cdot128=16{,}384\) B + output \(128\cdot128\cdot16=262{,}144\) B \(=278{,}528\) B > 262,144 B. RAM: fails by about 16 KB.
  3. MACs: Conv1 2,359,296 + Conv2 18,874,368 + Conv3 18,874,368 + Dense 256 ≈ 40.1 M → 0.40 s per image = 2.5 images/s. Speed: fails.
  4. Fix: stride 2 in Conv1. Conv1 output 64 × 64 × 16 (peak RAM \(16{,}384+65{,}536=81{,}920\) B); after pooling Conv2 runs at 32 × 32 and Conv3 at 16 × 16. MACs: 589,824 + 4,718,592 + 4,718,592 ≈ 10.0 M → 0.10 s, about 10 images/s.

The original design fits flash but fails RAM and speed. A stride-2 first layer brings peak RAM to 80 KB and throughput to about 10 images/s; accuracy must then be re-checked on validation data. A dense MLP (2.1 M parameters) would not even fit the flash.

10. Concept map

flowchart TD
  IMG["Image / spectrogram<br/>/ wafer map"] --> CONV["Convolution layer"]
  CONV -->|uses| K["Kernel (filter)<br/>shared weights"]
  K -->|sees a| RF["Local receptive field"]
  CONV -->|controlled by| PS["Padding & stride<br/>O = ⌊(N+2P−F)/S⌋+1"]
  CONV -->|produces| FM["Feature maps"]
  FM --> RELU["ReLU non-linearity"]
  RELU --> POOL["Pooling<br/>(max / average)<br/>no parameters"]
  POOL -->|repeat: deeper,<br/>smaller, richer| CONV
  POOL --> CLS["Flatten or global<br/>average pooling → Dense → Softmax"]
  CLS --> OUT["Class probabilities"]
  K -.->|why it works| WS["Weight sharing →<br/>few parameters,<br/>translation invariance"]
  CONV -.->|cost| COST["MACs & activation<br/>memory dominate"]
  COST -.->|matters for| EDGE["Embedded / TinyML<br/>(Module 4)"]
  CLS -.->|evolves into| ARCH["LeNet → AlexNet → VGG<br/>→ ResNet (Module 3)"]

11. Quick check

Q1. A 64 × 64 × 3 input goes through 16 filters of 5 × 5, stride 1, “valid”. What is the output shape?

    1. 64 × 64 × 16
    1. 60 × 60 × 16
    1. 60 × 60 × 3
    1. 59 × 59 × 16

Q2. How many parameters does that layer have?

    1. 1,216
    1. 1,200
    1. 400
    1. 76

Q3. The main reason a CNN needs far fewer parameters than an MLP on the same image is:

    1. pooling
    1. ReLU
    1. weight sharing
    1. dropout

Q4. During training, a convolutional layer mostly consumes:

    1. parameters
    1. disk space
    1. bias terms
    1. RAM for activations

Q5. Three stacked 3 × 3 convolutions (stride 1) have a receptive field of:

    1. 3 × 3
    1. 5 × 5
    1. 7 × 7
    1. 9 × 9
  1. (b) \(64-5+1=60\); depth equals the number of filters, 16.
  2. (a) \((5\cdot5\cdot3+1)\cdot16=76\cdot16=1{,}216\).
  3. (c) One filter is reused at every position; pooling has no parameters but is not the main saving.
  4. (d) Feature maps for every position and filter are stored for backpropagation (N3: 12.8 MB per image).
  5. (c) \(L(F-1)+1=3\cdot2+1=7\).

12. Questions and answers

Short-answer questions (2–4 marks)

  1. Define receptive field, stride and feature map.
  2. State two reasons why pooling is used in a CNN.
  3. Differentiate between “valid” and “same” padding with an example.
  4. Why does a CNN need a non-linear activation after each convolution?
  5. What is the difference between convolution in signal processing and the operation computed by a CNN layer?
  1. Receptive field: the region of the input that one neuron sees. Stride: the step between successive filter positions. Feature map: the 2-D output of one filter applied across the whole input.
  2. It reduces the spatial size (and so computation, memory and later parameters), and it makes the response tolerant to small shifts of the feature.
  3. Valid: no padding, output \(\lfloor(N-F)/S\rfloor+1\) (e.g. 32 → 28 for a 5 × 5 filter). Same: zeros added so the output is \(\lceil N/S\rceil\) (32 → 32).
  4. Without it, a stack of convolutions is just one linear filter and cannot represent complex, non-linear decision boundaries.
  5. Signal-processing convolution flips the kernel; CNN libraries compute cross-correlation without flipping. Because the kernel is learned, the network simply learns the flipped version.

Long-answer questions (8–10 marks)

  1. With a neat diagram, explain the architecture of a CNN for classifying wafer-map defect patterns. Label every layer with its output shape and explain the role of each layer.
  2. Derive the expressions for the output size, number of parameters and number of multiply–accumulate operations of a convolutional layer. Apply them to a layer of 32 filters of 3 × 3 on a 128 × 128 × 3 input with stride 1 and “same” padding.
  3. Compare LeNet-5, AlexNet and ResNet. Explain what problem each one solved and why depth alone is not enough to improve accuracy.
  1. Draw Figure 3: input 64 × 64 × 1 → Conv 32 → 64 × 64 × 32 → pool → 32 × 32 × 32 → Conv 64 → 32 × 32 × 64 → pool → 16 × 16 × 64 → flatten 16,384 → Dense 128 → Dense 8 softmax. Roles: convolution extracts local features with shared weights; ReLU adds non-linearity; pooling down-samples; dense layers combine features into a decision; softmax gives class probabilities. Mention class imbalance and augmentation for real wafer data.
  2. Output \(\lfloor(N+2P-F)/S\rfloor+1\) (from counting filter positions); parameters \((f_hf_wC_\text{in}+1)C_\text{out}\) (one shared filter per output channel); MACs \(O_hO_wC_\text{out}f_hf_wC_\text{in}\) (one filter evaluation per output value). For the example: output 128 × 128 × 32; parameters \((27+1)\cdot32=896\); MACs \(128\cdot128\cdot32\cdot27=14{,}155{,}776\).
  3. LeNet-5: first practical CNN, small, average pooling and tanh. AlexNet: much deeper and wider, ReLU, dropout, GPU training and augmentation, which made large-scale image recognition practical. ResNet: plain very deep networks train worse (degradation and vanishing gradients); skip connections let layers learn a residual \(f(x)-x\), so depths of 50–152 become trainable.

Key takeaways

  • A CNN replaces “every input connects to every neuron” with small filters shared across the whole image.
  • Output size: \(\lfloor (N+2P-F)/S \rfloor + 1\). Parameters: \((f_hf_wC_\text{in}+1)C_\text{out}\).
  • Convolutional layers are cheap in parameters but expensive in computation and activation memory; this decides whether a model fits an embedded device.
  • Pooling has no parameters; it shrinks feature maps and adds shift tolerance.
  • Depth grows the receptive field; stacks of small 3 × 3 kernels are more efficient than one large kernel.

Media for this lesson

Generated figures (in figs/, re-created by assets/make_cnn_figs.py): convolution example, PCB feature maps, CNN pipeline.

Stock photos to download (Pexels, free licence; Freepik needs attribution):

  • Pexels search “printed circuit board macro” for the analogy section.
  • Pexels search “semiconductor wafer” for section 8.
  • Freepik search “convolutional neural network vector” for a cover illustration.

Higgsfield video prompt (about 8 s, 16:9): “Clean technical animation on a dark navy background: a glowing 3×3 orange grid slides step by step across a large grey grid representing a circuit-board image; at each step a single cell lights up in a smaller blue grid on the right, building a feature map line by line. Minimal, flat style, no text, smooth camera, educational.”

Higgsfield video prompt (about 6 s): “Flat infographic animation: a stack of image layers moves left to right through blocks labelled by colour only; each block makes the stack thinner and deeper, ending in a single glowing bar chart. Calm motion, white background, blue and orange accents, no text.”

References

  1. Y. LeCun, L. Bottou, Y. Bengio and P. Haffner, “Gradient-based learning applied to document recognition,” Proceedings of the IEEE, 1998.
  2. T. Nakazawa and D. V. Kulkarni, “Wafer map defect pattern classification and image retrieval using convolutional neural network,” IEEE Trans. Semiconductor Manufacturing, 2018.
  3. M. Saqlain, Q. Abbas and J. Y. Lee, “A deep convolutional neural network for wafer defect identification on an imbalanced dataset in semiconductor manufacturing processes,” IEEE Trans. Semiconductor Manufacturing, 2020.
  4. E. Shin et al., “Efficient convolutional neural networks for semiconductor wafer bin map classification,” Sensors, 2023.
  5. S. Brockmann and T. Schlippe, “Optimizing convolutional neural networks for image classification on resource-constrained microcontroller units,” Computers, 2024.
  6. R. David et al., “TensorFlow Lite Micro: Embedded machine learning on TinyML systems,” arXiv, 2020.
  7. J. Lin et al., “Tiny machine learning: Progress and futures,” IEEE Circuits and Systems Magazine, 2023.
  8. A. Géron, Hands-On Machine Learning with Scikit-Learn, Keras & TensorFlow, 3rd ed., O’Reilly, 2023, Ch. 14.
  9. I. Goodfellow, Y. Bengio and A. Courville, Deep Learning, MIT Press, 2016, Ch. 9.