Zooming into a pixel: the simulated demo
A car on a highway interchange, about 20 pixels long in the recording, followed through six seconds and
enlarged four times by two networks: the compact one that runs on the TPUle, and the large RRDBNet for comparison.
Simulated: no board was involved. The compact network's output here is computed on the host by the integer
reference model, which gives the bytes the unit has to return. RRDBNet's is computed the same way, by its integer model; the
program that runs it on the unit is not written yet.
At the clip's speed, 30 frames a second. From the left: the scene with the tracked window; the view as
recorded (32 x 26 pixels, cut at whole pixels); the view enlarged by bicubic interpolation; by the compact network;
by RRDBNet. The enlarged views are stabilised on the car's front: it stays in place while the road moves past.
The two networks side by side
Bicubic interpolation, the compact network, RRDBNet; each frame shown four times.
Slower
The same frames, each shown four times.
What is shown
- The clip: "Jane M. Byrne Interchange Traffic", Wikimedia Commons, CC BY-SA 4.0 (Sea Cow): 1080p from a drone,
180 frames.
- The tracking is computed beforehand on the host (
demo/prep.py): the frames are stabilised, a small
moving object is found and followed, and for every frame a window of 38 x 32 pixels is cut around it at whole pixels.
- The stabiliser locks onto the car's front. The tracker knows the car to a whole pixel; the path is then measured
to a fraction of a pixel by registering a disk at the car's front (7 pixels ahead of its centre, radius 9) from each
frame to its neighbour, and smoothed over the track. A measurement counts only when the two disks correlate (0.92 or
more) and the point stays within 3 pixels of the tracker's smoothed path; a lamp post that passes over the car is
skipped this way. The network still runs on a window cut at whole pixels; the view shown is taken
out of the enlarged picture at the path's fraction, in steps of a quarter of a recorded pixel.
- The compact network is realesr-general-x4v3 with 8-bit weights and activations: 34 convolutions of 3 x 3 with 64
channels, about 1470 million multiply-adds for one window. It is calibrated once on the clip's middle frame.
- The fourth panel is the network in integers exactly as the unit computes it: sums of int8 products,
then each sum requantised to int8 (bias, multiplier, PReLU slopes, two shifts). The last layer's 48 channels become
the 4 x 4 sub-pixels of every pixel and are added to the window enlarged by pixel repetition.
- The fifth panel is the second model, RealESRGAN_x4plus: RRDBNet with 23 residual-in-residual dense blocks,
351 convolutions, about 21.8 thousand million multiply-adds for one window, 15 times the compact network. It is
written as a program of three operations on int8 maps (
demo/rrdb_ref.py): a convolution over several maps
at once (a dense block's convolution reads up to five) with the same requantisation as the compact network, a
residual add with a multiplier per channel (93 of them), and a doubling of the map. The panel is that program in
integers; against the float network it reaches 37 dB on this clip's windows.
- RRDBNet on the unit is prepared, not run: the convolutions are 24333 matrix products for one window, the
compact network's 1020. The compact network has run in the simulation of the KX2's design, all 34 layers equal to the
reference bytes, in 8.1 million clocks of the unit: 40.5 ms a window at 200 MHz, 24 windows a second (the simulation's
memory, not the board's DDR3). At that rate a product RRDBNet's window is about 1 s, computed, not measured. The
residual add is not an operation of the unit yet; until it is, the hart adds.
- On the board the same bytes come from the matrix array (the products) and the VPU (the requantisation). The
board's result is checked against these bytes, layer by layer.
Making it again
make -C ../demo fetch # the clip (Wikimedia Commons) and the float weights (Real-ESRGAN), once
make -C ../demo prep # the clip tracked, the windows, the network, the references
make -C ../demo prep-rrdb # the second model on the windows (64 MB of weights; some 20 minutes)
python3 make.py # zoom.mp4, zoom_slow.mp4, poster.jpg