Writing Machine learning & evaluation

A classifier has an answer for everywhere

The network in the last post takes six reflectances for a pixel and returns a land-cover class. It has only ever been shown pixels from one July afternoon over Pasco, Washington. But it is a function, and a function has a value at every input. It has an answer for a surface twice as bright as anything in the scene. It has one for a spectrum with a negative reflectance, which nothing can have.

This post draws that function as a landscape you can fly over, and trains it while you watch.

Six numbers, two axes

A pixel here is six numbers, so the network’s input is a point in a six-dimensional space, and a screen can show two of those dimensions with a third for height. Rather than pick two bands, I cut a flat slice through the space where the scene is widest. Take all 345,600 pixels and find the direction along which they vary most, then the direction at right angles to it along which they vary most again.

In this scene the first direction is overall brightness, all six bands rising together. The second is near infrared rising while the visible bands fall, which is what a leaf does. Kauth and Thomas found much the same two axes in Landsat images of farmland in 1976 and named them brightness and greenness. Here they hold 93% of the variance between pixels, so the slice passes close to nearly all of them.

Every point on the slice is a complete six-band spectrum, so the network can be asked about it. The height of the surface is how sure the network is of its top answer, from a six-way guess at the floor to certainty at the top. The colour is the answer. The dots are 2,400 real pixels, coloured by their WorldCover label and set down at the point of the slice nearest to them. The network judges a pixel on all six bands and the slice keeps two directions, so a dot of one colour on ground of another is sometimes a wrong answer and sometimes the 7% the slice leaves out.

The finished surface seen from above and to one side. Six coloured plateaus, one for each land-cover class, meet in narrow valleys at a small cluster of dots near the middle, and run out flat and high to the edges of the plane, far past the dots.
Starting weights
Camera
The network trains in your browser when the figure loads, from random weights, on the 230,380 labelled pixels of the training blocks. Play, or drag the slider, to move through its 6,000 steps. The slider spends half its travel on the first 1,500, where most of the change is. Drag the surface to turn it, use the arrow keys, and pinch or hold Ctrl and scroll to zoom. Full colour is the part of the slice where the scene has pixels. The pale part has none. The striped part is spectra with a band below zero. Contour lines are every ten points of confidence. On a phone, or with reduced motion set, this is a still of the finished surface until you start it. Contains modified Copernicus Sentinel data, 2021. Land cover © ESA WorldCover project 2021, CC BY 4.0.

Watching it train

At step zero the weights are random and the surface is whatever they happen to make. That network calls 40% of the scene crops and none of it bare ground, and agrees with WorldCover on 26% of a sample of held-out pixels. Twenty steps later it is past half, and by step 150 it is at 70%.

The classes arrive in order of how easy they are to cut off. Water is dark in every band and sits alone at one end of the brightness axis, and by step 10 the network finds 99% of the held-out water pixels. Crops follow by step 40. Trees are at 18% at step 80 and take until about step 600 to reach the 55% or so they finish on. Bare ground, the smallest class, is at 1% at step 300 and finishes at 18%.

By step 1,200 the network agrees with WorldCover on 74.6% of the sample. The remaining 4,800 steps add half a point, to 75.1%.

Now run it again and watch the pale part of the surface. At step 300 the network is over 90% sure of its answer on 1% of the slice that no pixel reaches. At step 1,200 that is 50%. At the end it is 66%. The score stopped moving a fifth of the way through, and the plateaus out where there is no data kept rising for the rest of the run.

Surest where it has seen nothing

The pixels take up very little of the slice. Nine in ten of them sit on 7% of it. Counting every point that has even one pixel, the scene covers 27%. Another 35% is spectra that could exist and that no pixel in the scene has. The last 38% has a band below zero.

The finished network is over 90% sure on 15% of the part with pixels, 66% of the empty part, and 85% of the impossible part. The other two starting points give 6%, 38% and 73%, and 5%, 55% and 67%. The order is the same each time: the further from the data, the surer the answer.

That follows from how the network is built. Each of its units is a straight line with a bend at zero, so the whole network is flat facets joined at creases. Far enough out there are no creases left to cross, and every class score is a plane. Two planes that cross keep separating at a constant rate, and the last step of the network turns a growing gap between scores into a probability approaching one. Hein, Andriushchenko and Bitterwolf proved in 2019 that this happens along almost every direction out of the data for any network of this kind.

Press From above and it is plain to see. The classes are wedges fanning out from the cluster of dots. Each boundary was put where it separates two crowds of pixels, and then carries on in a straight line to the edge of the drawing.

Among real pixels the same confidence is worth something. A third of the held-out pixels get an answer the network is over 90% sure of, and it is right on 96% of them.

Train it again

Starting weights trains the same network on the same pixels from a different random start. The three score 74.8%, 75.3% and 75.6% on all 115,197 held-out pixels. Any two of them give the same class to 94% of the pixels in the scene, and all three agree on 91%.

On the crowded 7% of the slice, all three agree at 90% of points. Across the whole slice they agree at 57.5%. The first network gives bare ground 21% of the slice and the third gives it half a percent. One gives water 5% and another 13%. Switch between them with the camera above the surface: the middle barely moves, and the wedges swing.

The pixels fix the surface where they are. Everywhere else it is set by where the random weights started.

What a new scene does

A land-cover model gets used on scenes it was not trained on: the same valley in January, the next county, another sensor. Each of those moves pixels off the crowded part of the slice and out onto the pale part, and nothing in the model’s output says so. The confidence it reports measures distance from a boundary. It does not measure whether the model has been here before, and out there it is usually higher.

Knowing that takes something that looks at the input. One way is to measure how far a new spectrum sits from the training pixels. Another is to train a few copies and see whether they agree, which costs three trainings and no new theory. On this slice the three copies stop agreeing where the pixels run out.

Method

The scene, the six bands, the labels and the held-out blocks are those of the first post in this series, read from the images that page ships. The network is the 6-16-16-6 one from the last post, 486 numbers, trained here from scratch: 6,000 steps of Adam on batches of 256 pixels drawn at random from the training blocks, with a cosine learning-rate schedule from 0.003. Inputs are standardised by the training mean and standard deviation. The three runs differ only in the seed, which sets the starting weights and the batches. Every step’s weights are kept, so the slider shows real states of the network.

The slice is the plane through the mean spectrum of the scene spanned by the first two principal components of its six bands, 60% and 33% of the variance. It is drawn from −0.6 to 0.9 in brightness and −0.5 to 0.6 in greenness, in units of reflectance, on a grid of 121 by 89 points. A point has pixels if at least one of the 345,600 is nearer to it than to any other point. The readout scores a fixed sample of 20,000 held-out pixels. The figures in the text were measured in Chromium, and another browser can differ in the last digit.

Check it yourself

Live
The scene above trains the network in your browser and reports its own numbers under the drawing. Its code is surface.js, unminified, with no library.
Numbers
Every figure in the text comes from tools/surface-stats.js, which runs the page’s own code. The two axes come from tools/surface-plane.py.
Data
Sentinel-2A Level-2A, tile 11TLM, 8 July 2021, from the public archive on AWS. Labels are ESA WorldCover 2021 v200, doi:10.5281/zenodo.7254221.

References

  1. M. Hein, M. Andriushchenko, J. Bitterwolf. “Why ReLU networks yield high-confidence predictions far away from the training data and how to mitigate the problem.” Proceedings of CVPR, 2019, pp. 41–50.
  2. G. Montúfar, R. Pascanu, K. Cho, Y. Bengio. “On the number of linear regions of deep neural networks.” Advances in Neural Information Processing Systems, 27, 2014. The facets and creases.
  3. R. J. Kauth, G. S. Thomas. “The tasselled cap: a graphic description of the spectral-temporal development of agricultural crops as seen by Landsat.” Proceedings of the Symposium on Machine Processing of Remotely Sensed Data, Purdue University, 1976, pp. 4B-41 to 4B-51.
  4. C. Guo, G. Pleiss, Y. Sun, K. Q. Weinberger. “On calibration of modern neural networks.” Proceedings of ICML, PMLR 70, 2017, pp. 1321–1330. Confidence that keeps growing after accuracy has stopped.
  5. B. Lakshminarayanan, A. Pritzel, C. Blundell. “Simple and scalable predictive uncertainty estimation using deep ensembles.” Advances in Neural Information Processing Systems, 30, 2017. Retrained copies as a measure of doubt.
  6. M. Drusch et al. “Sentinel-2: ESA’s Optical High-Resolution Mission for GMES Operational Services.” Remote Sensing of Environment, 120, 2012, pp. 25–36.
  7. D. Zanaga et al. ESA WorldCover 10 m 2021 v200. Zenodo, 2022. doi:10.5281/zenodo.7254221. The reference labels.
All writing Get in touch