Neural network fundamentals compressed onto one page: the definitions, formulas and numbers to have in your head before a quiz or exam.
Vocabulary and the two counts
Parameters are stored (flash), activations are computed per input (SRAM). A network fits a microcontroller only when both fit: the STM32F746 has 320 kB SRAM and 1 MB flash, and ResNet-50's 25.6 M parameters are about 100 MB in fp32. Part 01: Neurons and linear layers
yj=f(i∑wixi+b)
One neuron: c_i weights, one bias, one activation function
Diagram element
Names
Behaviour
Memory
Edge
Synapse, weight, parameter
Stored after training, one per connection
Flash
Node
Neuron, feature, activation
Recomputed for every input, one per computed unit
SRAM
Bias
One per neuron, never per edge
Stored, counted with the weights
Flash
Width
Size of a hidden layer
Goodfellow, Bengio and Courville
Depth
Number of layers in the chain, input row not counted
5-4-3-2 is a 3-layer network, 2 hidden
Synonym families and where each count lives
Fully connected layer and MLP
Y=XWT+b,yi=j∑wijxj+bi
W is (c_o, c_i), indexed (output, input), matching PyTorch nn.Linear
Shapes and counts
X
(n, c_i)
W
(c_o, c_i)
b
(c_o,)
Y
(n, c_o)
Parameters
c_o × c_i + c_o
Activations per sample
Sum of layer widths, plus the input if budgeting memory
Network
Weights
Biases
Parameters
Activations per sample
Slide 4, 5-4-3-2
20 + 12 + 6 = 38
4 + 3 + 2 = 9
47
9
Slide 5, 5 to 3
15
3
18
3
Slide 7, 5 to 3 to 2
15 + 6 = 21
3 + 2 = 5
26
5 (10 with inputs)
CS231n, 3-4-4-1
12 + 16 + 4 = 32
4 + 4 + 1 = 9
41
9
MNIST 784 to 128
100,352
128
100,480 (392 KiB fp32)
912 (7,296 at n = 8)
Worked parameter and activation counts
Convolution shapes and output size
Each output sees only the k inputs in its receptive field (sparse) and the same filter is reused at every position (weight sharing), so the parameter count never depends on h_i or w_i. Part 02: Convolution layers
Tensor
Fully connected
1D conv
2D conv
X
(n, c_i)
(n, c_i, w_i)
(n, c_i, h_i, w_i)
Y
(n, c_o)
(n, c_o, w_o)
(n, c_o, h_o, w_o)
W
(c_o, c_i)
(c_o, c_i, k_w)
(c_o, c_i, k_h, k_w)
b
(c_o,)
(c_o,)
(c_o,)
Tensor shapes, PyTorch order, output channels first in W
ho=⌊shi+2p−kh⌋+1,p=2k−1 keeps the size at s=1
General output size; p = 0 and s = 1 give h_i - k_h + 1
h_i
k
s
p
Arithmetic
h_o
4
3
1
0
(4 - 3)/1 + 1
2
4
2
2
0
(4 - 2)/2 + 1
2
5
3
1
1
(5 + 2 - 3)/1 + 1
5
32
5
1
0
(32 - 5)/1 + 1
28
32
5
1
2
(32 + 4 - 5)/1 + 1
32
32
5
2
2
floor(31/2) + 1
16
8
3
2
0
floor(5/2) + 1
3, not 3.5
224
7
2
3
floor(223/2) + 1
112
Output height for the configurations in the lecture
g must divide both c_i and c_o. Depthwise is g = c_i = c_o, one k × k filter per channel
Layer
W shape
Weights
Weights + biases
Fewer than standard
Standard, g = 1
(64, 64, 3, 3)
36,864
36,928
1×
Grouped, g = 2
(64, 32, 3, 3)
18,432
18,496
2×
Grouped, g = 4
(64, 16, 3, 3)
9,216
9,280
4×
Grouped, g = 8
(64, 8, 3, 3)
4,608
4,672
8×
Depthwise, g = 64
(64, 1, 3, 3)
576
640
64×
Depthwise + 1 × 1 pointwise
(64, 1, 3, 3) + (64, 64, 1, 1)
576 + 4,096 = 4,672
4,800
7.9×
c_i = c_o = 64, k = 3, biases included in the fourth column
Depthwise separable cost ratio (Howard et al.): 1/N + 1/D_K², so 1/64 + 1/9 ≈ 0.127, about 7.9× cheaper. On a 56 × 56 map: 115.6 M MACs standard against 14.7 M separable. A depthwise layer never mixes channels; the 1 × 1 pointwise layer (c_o · c_i weights) restores mixing. Grouped convolution does not change h_o, w_o or c_o.
Pooling
A fixed summary of a window inside each channel independently: spatial size drops, channel count unchanged, zero parameters. Part 04: Pooling and CNN features
The convolution formula with p = 0 and the kernel renamed F; PyTorch floors unless ceil_mode
Max pooling
Average pooling
What it returns
Largest value in the window
Mean of the window
Shift by one cell
Usually unchanged (approximate translation invariance)
Changes slightly
Gradient
Routed to the argmax cell only
1/F² to every cell
Typical place
Inside the trunk after a conv block
Global average pool as the head
Slide 22 slice, F = 2, S = 2
[[6, 8], [3, 4]]
[[3.25, 5.25], [2, 2]]
Max against average
Input, F, S
Arithmetic
Output
224, F = 2, S = 2
(224 - 2)/2 + 1
112, activations 3,211,264 to 802,816
224, F = 3, S = 2
(224 - 3)/2 + 1 = 111.5
111 floored, 112 with ceil_mode
55, F = 3, S = 2 (AlexNet)
(55 - 3)/2 + 1
27
56 × 56 × 128, F = 3, S = 2
(56 - 3)/2 + 1 = 27.5
27 × 27 × 128
4, F = 3, S = 2
(4 - 3)/2 + 1 = 1.5
1 × 1, value [[7]]
Pooling configurations worked
Feature hierarchy and full network counts
Tier
Layers
Responds to
Receptive field
Low
First conv layers
Oriented edges, bars, blobs
3 × 3 to 11 × 11 px
Mid
Middle layers
Eyes, wheels, tusks, chair legs
tens of pixels
High
Deepest layers
Whole faces, cars, elephants, chairs
most of the image
Edges, parts, objects (Lee et al. 2009; Zeiler and Fergus 2013)
Layer
Output
Parameters
input
32 × 32 × 3
0
conv 16 × 5 × 5 × 3, pad 2
32 × 32 × 16
1216
max pool 2, stride 2
16 × 16 × 16
0
conv 20 × 5 × 5 × 16, pad 2
16 × 16 × 20
8020
max pool 2, stride 2
8 × 8 × 20
0
conv 20 × 5 × 5 × 20, pad 2
8 × 8 × 20
10,020
max pool 2, stride 2
4 × 4 × 20
0
softmax 320 to 10
10
3210
Total
22,466
ConvNetJS CIFAR-10 demo (slide 25)
Layer
Output
Parameters
input
64 × 64 × 3
0
conv_1_1, 10 × 3 × 3, valid
62 × 62 × 10
280
conv_1_2, 10 × 3 × 3, valid
60 × 60 × 10
910
max_pool_1, 2, stride 2
30 × 30 × 10
0
conv_2_1
28 × 28 × 10
910
conv_2_2
26 × 26 × 10
910
max_pool_2
13 × 13 × 10
0
flatten 1690, dense 10
10
16,910
Total
19,920
CNN Explainer Tiny VGG (slide 26)
Only the first fully connected layer's count depends on image size (320 inputs in ConvNetJS, 1690 in Tiny VGG). The SRAM high-water mark is the largest activation tensor, in Tiny VGG the 62 × 62 × 10 = 38,440 output of the first conv.
Batch normalization
Inputs that are off-centre force a large bias; inputs with different scales force W entries to span magnitudes. BN standardizes each feature over the batch with a differentiable map inside the network. Part 05: Normalization
Per feature, over the batch. Biased variance during training
Shapes and defaults for a fully connected input
x, x_hat, y
N × D
mu, sigma squared
D, computed over the batch axis N
gamma, beta
D, the only learned parameters
eps, momentum (PyTorch)
1e-5, 0.1
Identity recovery
gamma = sqrt(sigma² + eps), beta = mu
BatchNorm2d over C channels
2C parameters, running mean and variance are buffers
W′=diag(σ2+εγ)W,b′=γ⊙σ2+εb−μ+β
BN fusion at inference: frozen running statistics make BN affine, so it folds into the previous linear or conv layer at zero cost
Normalization axes
x^i=σixi−μi,μi=m1k∈Si∑xk
Wu and He: one rule, the set S_i picks BN, LN, IN or GN
Normalization
Averages over
mu, sigma shape
gamma, beta shape
Same at train and test?
BN, fully connected
N
1 × D
1 × D
No
BN, convolution
N, H, W
1 × C × 1 × 1
1 × C × 1 × 1
No
Layer norm
D (or C, H, W)
N × 1
1 × D on slide 35, per channel in Wu and He
Yes
Instance norm
H, W
N × C × 1 × 1
1 × C × 1 × 1
Yes
Group norm, G groups
H, W and C/G channels
N × G × 1 × 1
1 × C × 1 × 1
Yes
The family on a conv activation of shape N × C × H × W
Norm
mu shape
Values per mean
BN
1 × 64 × 1 × 1
8 × 32 × 32 = 8192
LN
8 × 1 × 1 × 1
64 × 32 × 32 = 65,536
IN
8 × 64 × 1 × 1
32 × 32 = 1024
GN, G = 32
8 × 32 × 1 × 1
2 × 1024 = 2048
Worked on 8 × 64 × 32 × 32
Row
Feature 1
Feature 2
Feature 3
After ReLU
3, 1, 3, 2
0, 2, 3, 0
0, 5, 2, 0
Mean (divide by N = 4)
2.25
1.25
1.75
Variance (biased)
0.6875
1.6875
4.1875
Standard deviation
0.829
1.299
2.046
x_hat
0.905, -1.508, 0.905, -0.302
-0.962, 0.577, 1.347, -0.962
-0.855, 1.588, 0.122, -0.855
gamma, beta
2, 0
3, 0
-1, 1
y
1.81, -3.02, 1.81, -0.60
-2.89, 1.73, 4.04, -2.89
1.86, -0.59, 0.88, 1.86
Check: mean beta, variance gamma²
0, 4
0, 9
1, 1
Slide 38 batch norm by hand (W = [[1, 0, 1], [1, 1, 0], [0, 2, -1]], b = (0, -1, 0), then ReLU, then BN)
Activation functions
Without a nonlinearity stacked linear layers collapse into one. On an MCU the two questions are: does it need an exponential, and is the output bounded? Part 06: Activations and transformers
Output size is written without the floor. Use floor((h_i + 2p - k)/s) + 1: 8, 3, 0, 2 gives 3, not 3.5.
Slide 20
Depthwise W is written (c, k_h, k_w); frameworks store (c, 1, k_h, k_w). Keep four axes.
Slide 21
"Max pooling performs a lot better" is an empirical heuristic (Boureau et al. 2010); modern trunks use strided convs and global average pooling. Stray capital "It".
Slide 24
"fully connecter layer" should be "fully connected". The FC bars are class scores, probabilities only after a softmax.
Slide 25
The ConvNetJS URL is printed with http://; the live page is https://.
BN is placed after the ReLU; the paper, CS231n and Goodfellow put it before the nonlinearity. Only the paper order allows fusion. Values are heavily rounded; recompute with biased variance.
Slide 43
q2 is drawn as (1, 1, 1) but equals (1, 1, 2), so column 2 scores are 2, 3, -1, 2 and z2 = (12, 4, 3), not (8, 4, 4). The drawing uses column vectors, K^T Q and Z = V A.
Slide 44
Hidden row 4 shows -9 and -4; the arithmetic gives -8 and -3. ReLU zeroes both, so the outputs stand. The attention matrix columns sum to 2, not a softmax.
Reference deck: MIT 6.5940 lecture 2 (Song Han), which slides 2 to 20 reproduce, including the Layer 0 and w42 labels.
By-hand worksheets (slides 38, 43, 44) are Tom Yeh's and round heavily; recompute before quoting.