fenet
A neural network that runs inside SVG filters: draw a digit in box 1, and a chain of 620 filter primitives reads it in box 2.
Works in Chrome, Edge, Brave, Arc and Firefox, best with a mouse. Safari, and anyone curious first: watch the recording.
fenet needs Chrome, Edge, Brave, Arc or Firefox on a computer or an Android phone (on iPhone and iPad every browser uses Safari's engine). This browser's SVG filters differ in ways the network can't absorb yet, so it would misread your drawing. Here is a recording of it in Chrome:
Bars: the network's score for each digit. The highest wins.
The filter has to know the size of a screen pixel, and this zoom level isn't on its list. Set the browser zoom to 100% to see the reading.
In Firefox the filter reads correctly only when a CSS pixel is a whole number of screen pixels: 1, 2, 3 or 4. This zoom level gives a fraction. Try another zoom level (67% on a screen scaled to 150%, 80% at 125%), or Chrome.
One reading, step by step: the opening 5
Your strokes 14 × 14 cells on the pad.
Pixels 196
:has()rules copy the cells into screen pixels; a threshold and a 3 × 3 blur follow.Layer 1: 192 neurons Each is one
feConvolveMatrix: 196 weights over the whole image, plus a bias, clamped to 0…1; anfeOffsetputs it in one pixel.Layer 2: 96 neurons The same, reading layer 1's image.
Scores Ten more neurons, one per digit.
Answer
feMorphologyfinds the highest score; a second filter prints it.
How it reads
CSS paints the cells. While the mouse button is down over the pad, the cell under the pointer turns dark. A painted cell stays dark because its transition back waits a million seconds.
.grid:active rect:hover { transition: fill 0s; } .grid rect { transition: fill 0s 1000000s; }196
:has()rules copy the drawing into a 14 × 14 square of screen pixels inside box 2. Media queries scale it by one over the device pixel ratio, so each cell is exactly one pixel.Each neuron is one
feConvolveMatrix. Centred on the middle pixel, its 15 × 15 kernel covers the whole image: a weighted sum plus a bias, clamped to 0…1 like every filter result. AnfeOffsetmoves that one value to the neuron's own pixel. Layers of 192, 96 and 10 neurons follow a 3 × 3 blur.<feConvolveMatrix order="15" targetX="7" targetY="7" kernelMatrix="…196 weights…" bias=".003726" x="0" y="0" width="14" height="14" result="n" …/> <feOffset in="n" dx="-2" dy="-6" x="5" y="1" width="1" height="1"/>
Morphology picks the winner.
feMorphologydilates the ten scores to their maximum,feCompositecomputes 1 + score − maximum, and a lookup table keeps the pixel that came out exactly 1. One more convolution settles ties in favour of the lower digit.A second filter prints the answer. It reads each digit's winner flag and score from the red and green channels of its slot, spreads them with
feTile, and uses them to mask a dot-matrix digit and ten bars.
Specification
- Network
- 196 → 192 → 96 → 10
- Weights
- 57,322
- Filter primitives
- 620 in the network, 300 of them convolutions
- Largest kernel
- 225 taps (Chromium's limit is 256)
- MNIST test digits
- 96.7% correct
- Same, one-cell strokes
- 95.0% correct
- Pen-written digits
- 94.8% correct, by 14 writers it never saw (UCI Pendigits)
- Filter vs. model
- same answer as the NumPy model on all 1,600 test digits in Chromium (200 at each of 8 zoom levels, GPU and software raster alike) and all 800 in Firefox (200 at each of 4 zoom levels)
- Zoom levels
- 76 device pixel ratios from 0.5 to 5 in Chromium, 1 to 4 in Firefox; others show a note
- JavaScript
- none
Built for Chromium browsers (Chrome, Edge, Brave, Arc) and Firefox; Firefox reads at zoom levels that make a CSS pixel a whole number of screen pixels. Safari gets the recording. Trained in NumPy on MNIST, reduced to 14 × 14 cells and thinned to look like mouse strokes, and on pen-written digits from UCI Pendigits, with every activation rounded to 8 bits as the browser stores it.