Writing Machine learning & evaluation
A scene made of blobs
The scene below was made from 251 photographs of an old turquoise truck parked on a plaza, and from nothing else. There is no mesh in it and not one triangle. It is 300,000 coloured blobs with soft edges, and drawn on top of each other in the right order they look like a truck.
The method is 3D Gaussian splatting, which Kerbl, Kopanas, Leimkühler and Drettakis published in 2023. I like it because so little of it is hidden. Each blob is fourteen numbers you can read, and the scene is trained by taking a picture of it and comparing that picture with a photograph.
What a splat is
A splat is a 3D Gaussian. It has a centre, three axis lengths, a rotation that says which way the axes point, a colour and an opacity: 3 + 3 + 4 + 3 + 1 numbers. It is densest at the centre and fades smoothly outward, so it has no edge.
Press Each splat to take the fade away. Every splat is then a solid disc, cut off where it has faded to about a third of its peak. Very few of them are round. On the paving they are flat flakes lying in the surface, and many of the rest are thin needles. Click one and the readout gives its three axes as fractions of the longest.
Drawing them takes three steps. Each 3D Gaussian is projected onto the screen, where it becomes a 2D ellipse. The splats are sorted by distance from the camera. Then they are blended in that order, so that a near splat covers part of what is behind it, by an amount set by its opacity and by how far the pixel is from its centre. On this page the projection runs in a vertex shader and the sort runs in a background thread each time the camera moves.
Where the cameras were
None of this can start without knowing where each photograph was taken from, and nobody wrote that down. It is worked out from the pictures. A structure-from-motion program, COLMAP here, finds corners and patches of texture that show up in several photographs. It then solves for the camera positions and for the 3D position of each matched patch together, because each fixes the other.
For this scene that gave 251 camera positions and 136,029 points. Drag the slider to its left end to see the points, and tick Cameras to see where the photographer stood: two laps around the truck.
Training is taking the photograph again
Training starts from those points and repeats one step 30,000 times. Pick one of the photographs. Draw the splats from where it was taken. Compare the drawing with the photograph, pixel by pixel. The projection, the fade and the blending are all smooth arithmetic, so the error at a pixel can be traced back to every number of every splat that touched it, and each number is moved a little in the direction that shrinks the error.
The trainer also adds splats where the picture stays wrong and removes ones that have faded out. I capped the count at 300,000 to keep the download small. This run had 138,436 splats at step 250 and 191,661 at step 2,000, and reached the cap by step 4,000. The remaining 26,000 steps only move, reshape and recolour what is there.
Press Replay training. At step 250 the truck is already there, as if seen through frosted glass, with a dark haze under it. By step 2,000 the boards have edges and the lettering on the door has appeared. Most of what a viewer would call the scene is in place by then, a fifteenth of the way through. The whole run took 4 minutes 12 seconds on one desktop graphics card.
Which photographs made a splat
A splat is only ever corrected by the photographs it shows up in. Click one at the last step and the three it shows in most come up under the scene, each with a ring where the splat lands. Red lines run to it from those three cameras.
Half of the splats show in 58 or more of the 251 photographs. A tenth show in 27 or fewer, and those are mostly background: the far buildings, the trees, the sky. They were seen from a narrow range of directions, so the photographs say what colour they are and little about how far away. Lift the camera above the laps the photographer walked and the street comes apart into streaks.
That is the limit of the method, and it comes from the photographs. The scene is right from where it was measured and from places near there.
What the photographs leave open
I first drew this scene five decibels worse than the trainer did, and the reason turned out to be the most interesting thing in the files. A colour channel on a screen stops at 1. In the trained scene, more than a quarter of the splats have a channel above that, and one reaches 3.17.
The trainer draws over black. Over black, a surface that is four fifths opaque and a quarter too bright gives exactly the same pixel as one that is solid and the right colour. The photographs cannot tell the two apart, so training has no reason to prefer the solid one. Across the 251 views, about 6% of the black behind the splats still shows through on average, and more than that through flat, plain surfaces: about a fifth through the paving in the one view I measured it in. I had clipped the colours to 1 when packing the file, which left those surfaces thin and dark.
It is the same thing as the smeared background. Where the measurements pin a quantity down, the scene has it right. Where they do not, it holds whatever value the optimiser happened to reach, and nothing in the result marks which is which.
How close it gets
Every eighth photograph, 32 of the 251, was kept out of training. Drawn by the trainer from those 32 positions, the finished scene matches the photographs to a peak signal-to-noise ratio of 24.85 dB, and the single views range from 21.4 to 27.5. At step 5,000 the mean was 23.84, so the last 25,000 steps bought one decibel.
The copy on this page is smaller than the trainer’s. Its file keeps 56 bytes for each splat and this page keeps 17. On four of the held-out views, the page scores 23.3 dB where the trainer scores 25.6. I also gave up two things before training to keep the size down. Each splat has one fixed colour, where the full method lets colour change with viewing direction, so the windscreen does not catch the light as you move. And 300,000 splats is few for a scene this size. The gravel and the small lettering are where it shows.
Why I keep coming back to this
A photograph is a measurement. It records how much light arrived along each of half a million directions through one point. Splatting takes 251 of them and asks what arrangement of colour and opacity in space would produce all of those measurements at once, then checks the answer by predicting measurements that were held back.
That is the same problem as the satellite work I do, where a pixel is a measurement and the map is the model that has to explain it. This version of it happens to produce something you can walk around.
Method
The photographs are the Truck scene of the Tanks and Temples benchmark, in the form the splatting authors distribute it: 251 images of 979 by 546 pixels with COLMAP camera poses and sparse points. I trained with Brush 0.3.0 for 30,000 steps on 219 images, holding out every eighth, with one colour per splat and a cap of 300,000 splats, and saved the scene every 250 steps. The slider shows six of those saves. The scores for the trainer are computed from the images it saved for the held-out views against the photographs.
For the page, each save is rotated so that up is up, scaled so the cameras sit about one unit from the truck, and written at 17 bytes a splat: 16 bits for each coordinate, in a space that squeezes everything beyond one unit into a shell, and 8 bits each for the logarithm of each axis length, each rotation component, each colour channel up to 2, and the square root of opacity. The page blends into a floating-point buffer and clips once at the end, as the trainer does. It draws over black wherever the splats cover most of a pixel and lets the page’s paper show only where they cover little.
The photographs listed for a splat come from drawing the packed scene from all 251 cameras at half size and adding up the weight each splat ends with in each view, after everything in front of it has taken its share. A splat counts as showing in a photograph if that weight is more than a twentieth of a pixel. Clicking picks the splat with the largest weight at that pixel.
Check it yourself
- Live
- The scene above is drawn by splat.js, unminified, with no library. The files it reads are listed in manifest.json.
- Photographs
- Truck, from Tanks and Temples by Knapitsch, Park, Zhou and Koltun, published under CC BY 4.0. The small copies shown here are resized from it.
- Held-out views
- Four of the 32 photographs kept out of training are in /assets/splat/ref/ (000001, 000065, 000129 and 000193). The page’s score against them comes from drawing the scene from each one’s camera and comparing pixels.
- Trainer
- Brush 0.3.0, with
--total-steps 30000 --sh-degree 0 --max-splats 300000 --eval-split-every 8and its other settings left alone.
References
- B. Kerbl, G. Kopanas, T. Leimkühler, G. Drettakis. “3D Gaussian Splatting for Real-Time Radiance Field Rendering.” ACM Transactions on Graphics, 42(4), 2023. doi:10.1145/3592433.
- A. Knapitsch, J. Park, Q.-Y. Zhou, V. Koltun. “Tanks and Temples: Benchmarking Large-Scale Scene Reconstruction.” ACM Transactions on Graphics, 36(4), 2017. doi:10.1145/3072959.3073599. The photographs.
- J. L. Schönberger, J.-M. Frahm. “Structure-from-Motion Revisited.” Proceedings of CVPR, 2016, pp. 4104–4113. doi:10.1109/CVPR.2016.445. COLMAP, which found the cameras.
- M. Zwicker, H. Pfister, J. van Baar, M. Gross. “EWA volume splatting.” Proceedings of IEEE Visualization, 2001. doi:10.1109/VISUAL.2001.964490. The projection of a 3D Gaussian to an ellipse on the screen.