A 6×6 image goes through a complete convolutional network: two 3×3 kernels, ReLU, 2×2 max pooling, flatten, a dense layer and softmax. Each stage has the matching NumPy or TensorFlow code, with the output it prints for the current values; open it with Show code. Draw by clicking pixels, and edit any kernel value, dense weight or bias. Section 7 trains the weights from scratch instead.
Every number in a neural network has one of four origins. Each stage below is tagged with the same labels, and the dots on the grid titles mark where each grid comes from.
.keras file) and loaded each time it's used.Here: kernel values, dense weights and biases, set by hand instead so the output is predictable.Labels, the correct answer for each training image, are a fifth source. They come with the dataset, usually from people annotating examples, and are only used during training to measure how wrong a prediction is. They never enter a prediction, so they don't appear below.
The 3×3 kernel slides over the image. Press Play, use the arrows, or hover any number to see which input pixels produced it. The kernel values are editable.
Both kernels run on the same image. Their two pooled 2×2 maps are laid end to end as one vector of 8 numbers. Nothing is computed here; the shape just changes from 2×2×2 to 8.
Each class has one row of 8 weights and a bias, all editable. Its logit is the dot product of that row with the flattened vector, plus the bias. Hover a row or edit a value to see its sum.
Start from random weights and let gradient descent find them. Each epoch runs all 54 example shapes through the network in batches of 8, and the optimizer nudges every weight against its gradient. To compare optimizers, train once, change the optimizer, and press Rerun from same start: the earlier loss curve stays on the chart. Steps 1–6 above update as the weights change.
Press Randomize weights to start from scratch, or train from the current hand-set weights.
Green border: the network currently classifies it correctly. Red: wrong. Click a shape to load it into the input above.
Takes the image in the input grid, compares the prediction with the answer you pick, and applies a single plain SGD update, whatever optimizer is selected above. This is the worked example from the explanation: rows move by (p − y) × x.
Training code for the current settings. No output is shown: training starts from random weights, so your numbers will differ from the page. Accuracy normally climbs to 0.9–1.0.