batchnorm -- running mean/variance + train vs inference
Numbers flowing through a deep network drift, one layer's outputs coming out ten times bigger than another's, and that makes training slow and fragile. This step fixes it by measuring, during training, the average and the spread of each channel — the picture one filter produces — across the current batch of images and dividing them out, so every channel arrives at the next layer on a comparable scale. Batches are small and noisy, so it also keeps a smoothed running estimate of those two numbers. That is the part that surprises people: once training is over there is no batch to measure, so the frozen estimate is used instead, and the network behaves slightly differently when you use it than it did while learning.
Interactive page: Batch Normalization -- normalize each channel's activations, track a running mean/variance during training (an exponential moving average), and at inference use that tracked average instead of the batch's own statistics. Anchor: F (CNN / vision); Family F, builds on convolution.
What it shows
For one channel of a feature map (the paintable input), BatchNorm computes y = γ · (x − μ)/√(σ² + ε) + β -- but which μ, σ it uses differs by mode:
- Training: use the current batch's mean/variance (so each batch is recentered to ~0 mean, unit variance), and update a running estimate:
running_μ ← (1−m)·running_μ + m·batch_μ(same for variance). Real batches are noisy, so the running average smooths the jittery per-batch stats -- the page tracksbatch_μ(jittery dots) vsrunning_μ(smooth line) converging to the true channel mean over steps. - Inference: there's no batch, so BN uses the frozen running mean/variance it learned. The consequence: a test input that's brighter than average comes out brighter (measured against the learned population) -- it is not recentered to zero the way training would. Toggle train ↔ inference on a bright input to see the output shift.
γ (scale) and β (shift) are learned per channel and let the network undo the normalization if it wants. BN does all of this independently per channel.
Drag (paint) the input to change its values and watch the running average drift to track it, and the normalized output respond; toggle train / inference; adjust momentum (EMA rate), γ, β. The training EMA animates.
Render tier
T1 (Canvas2D: the paintable input + normalized output grids, the running-statistics tracking chart).
Wiring
layout.mount + controls (shape, mode, momentum, gamma, beta, seed) + animate (the training EMA) + onPointer paint-the-input + hover. ?mode / ?shape / ?paint / ?hover hooks. Source: page.js.