zdeeno.cz

blog · robot navigation · neural networks

Matching a summer view to a winter map

A robot repeating a route needs one number from its camera: how far its view is shifted against the image it recorded. Here is how a small Siamese network gets that number when the recording is from winter and the robot drives in summer, or at night. You can run the network in your browser, on real image pairs.

One number, every day of the year

In appearance-based teach and repeat, the robot compares what it sees with the image it recorded at the same distance along the route, and turns towards the recorded scene. The first post in this series showed why that is enough to keep it on the route: the only thing the camera has to deliver is the horizontal shift between the two images.

For years, that shift came from local image features. Find distinctive points in both images (corners, blobs) with a detector like SIFT, describe each one, match the descriptions, and take the most common horizontal offset of the matched pairs. That works when the two images look alike. It fails when they do not: a tree in summer and the same tree in winter have almost no local details in common, and a car park at night is a few street lamps in the dark. A robot taught in one season stops being able to repeat its route in the next.

In our paper in Sensors we stopped matching points and trained a network to answer the one question directly: how far is this image shifted against that one?

Two copies of one network

A Siamese network is one network applied to two inputs. Ours is small: five convolutional layers, 1.4 million parameters, with no fully connected layer at the end. It turns a 512 × 192 image into a strip 64 columns wide and 4 rows tall, with 16 numbers in every cell. Each column describes an 8-pixel-wide slice of the image; the height is squeezed on purpose, so that a small tilt or bump of the camera matters less. The network in the paper kept 256 numbers per cell; the version on this page, the one our robot runs in visual teach and generalise, squeezes them into 16. A whole image then fits into 4,096 numbers, which keeps a map of thousands of images small.

To compare two images, slide one strip over the other. At every offset, multiply the overlapping numbers and add them up. The offset with the highest score is the shift. The strip is treated as a ring, wrapping round at the edges ("roll padding"), so that every shift is tried with the whole image.

MAP IMAGE · WINTERMAP REPRESENTATION · 64 × 4 × 16LIVE IMAGE · SUMMERLIVE REPRESENTATIONNETWORK · 5 LAYERSSAME NETWORK,SHARED WEIGHTSSLIDE AND SUM:SCORE OF EVERY SHIFT−248+256 PXPEAK: +32 PX → STEERTRAINING ONLY: COMPARE WITH A SPIKE AT THE TRUE SHIFT (DASHED), CORRECT THE WEIGHTS MAP · WINTER64 × 4 × 16LIVE · SUMMER64 × 4 × 16SHAREDWEIGHTSSLIDE AND SUM: SCORE OF EVERY SHIFT−248+256 PXPEAK: +32 PX → STEERTRAINING ONLY: THE TARGET IS A SPIKE ATTHE TRUE SHIFT (DASHED); THE DIFFERENCECORRECTS THE WEIGHTS
The whole pipeline, drawn from the pair in the demo below. Both images go through the same network; the coloured strips are its real output, with similar colours for similar descriptions. Sliding one strip over the other scores every shift, and the peak is the turn the robot makes. Only training adds the dashed part: the scores are compared with a spike at the true shift, and the difference corrects the network's weights.

slide one representation over the other

The real network output for this pair, computed once and stored.
Loading…

Look at the two coloured strips. The colours are the three directions in which the 16 numbers vary most, so cells with similar colours hold similar descriptions. The images could hardly look more different: snow and bare branches against full leaves. The strips, though, look alike, and once they are slid to the right offset the colours line up. The network has learned to describe the structure of the place, such as where the trunks, the lamp post and the bench are, and to ignore what the season paints over it.

Training without labels: find the cutout

Training a network to estimate shifts would normally need thousands of image pairs with the true shift annotated by hand. We avoided that with a simple game. Take two images of the same place from different seasons, cut a 56-pixel-wide strip out of one, and ask the network where that cutout lies in the other. The target is a spike: highest at the true position, falling linearly to zero over the width of the cutout. A single-pixel target made the network brittle, and a flat box made it imprecise; the spike gave both robustness and accuracy.

The game has a hidden bonus. Everything outside the cutout is a wrong answer, so every training example contains its own negatives, and the network cannot "collapse" into describing everything the same way, a classic failure of this kind of learning.

the training game, played by the trained network

Move the cutout and see where the network finds it.
Loading…

Where do the image pairs come from? We started with the Nordland dataset: a train filmed the same long railway line in Norway in all four seasons, and its GPS gives roughly matching frames. GPS alone is too coarse to train on, so the first network, trained on the coarse pairs, was used to re-align the dataset, picking for every winter frame the summer frame it matched best. The better-aligned pairs then trained a better network. We did the same with a year of city drives from the UTBM RobotCar dataset to add day and night, with the network annotating its own training data. The cutouts from Nordland were chosen to avoid the rails, because otherwise the network would happily learn to align rails and nothing else.

Try it: run the network in your browser

Below, the full network runs on your device: about three billion multiply-adds per image, in plain JavaScript, which takes about two seconds per image on a laptop. Pick a pair, turn the second camera with the slider, and see whether the network finds the turn you made.

the whole network, on your device

The network (2.8 MB) is downloaded only when you press Run.

On the car park pairs the two photos were taken from the same spot, so the right answer is exactly the turn you set. With raindrops on the lens the network finds it to within a pixel or two, and in the dark to within a bin (8 px). A single comparison can still go wrong, as the ambiguous cutouts in the training game above show, which is why the robot treats each one as a noisy measurement among many. "What it relies on" shows which parts of the image carry the match, from blue (little) to red (most): multiply the two representations cell by cell at the winning shift instead of summing everything. In the car park at night it leans mostly on the lamp posts and the fence.

How well it works

We compared the network with the feature-based methods used in teach and repeat (SIFT, and GRIEF, which was evolved specifically for seasonal changes; SuperPoint too, where it applied) on four datasets that the network never saw in training: a park, a university campus, the surroundings of a planetarium, and a car park by day and night. Every image pair had its true shift annotated by hand. The Siamese network was more accurate than all the others on all four, and the difference was statistically significant.

Evaluation datasetChangesMean errorWithin 32 px
Stromovka parkseasons12.3 px96.2 %
Carlevaris (campus)seasons18.8 px94.2 %
Planetariumseasons7.0 px99.4 %
Čestlice car parkday and night20.5 px91.6 %

Results from the paper, for its network with 256 numbers per cell, trained on both Nordland and UTBM RobotCar, on 512 px wide images. For scale, on Stromovka the hand-annotated correspondences within one image pair already differ by 17 px on average.

Then we put it on a vehicle: a prototype autonomous car transporter at the Škoda car factory in Mladá Boleslav, steered by the camera alone while a total station measured its position. Taught a 100 m path by day, it was moved about 2 m off the path and sent along it at night. It steered back onto the path. Taught a 100 m loop and displaced by about 4 m, it brought the error down lap after lap, by night and by day, to below 0.2 m. With SIFT or GRIEF in place of the network, the vehicle could not be guided reliably at night with a map taught by day.

The network has since become the eyes of our later work. Its likelihood of every shift, not just the best one, feeds the particle filter that also estimates where along the route the robot is, and its representations are what visual teach and generalise averages to follow paths it has never seen.

Read more

  1. Z. Rozsypálek, G. Broughton, P. Linder, T. Rouček, J. Blaha, L. Mentzl, K. Kusumam, T. Krajník: Contrastive learning for image registration in visual teach and repeat navigation. Sensors 22(8), 2975, 2022. Open access.
  2. Code, trained models and datasets: github.com/Zdeeno/Siamese-network-image-alignment.
  3. Z. Rozsypálek et al.: Multidimensional particle filter for long-term visual teach and repeat in changing environments. IEEE RA-L, 2023.

About the demos: the network is the 16-number model our robot runs (model_tiny in the VT&G code), the same architecture as the repository's 256-channel model with a narrower last layer. Batch normalisation is folded into the convolutions and the weights are stored as 16-bit numbers, which changes its output by under 1 %. It runs in a Web Worker. Shifts are found over the whole representation with roll padding, the scores turned into a likelihood the way the repository's demo does, and the peak refined between bins. The park images come from our Stromovka recordings and the repository's example; the car park images from a long-term dataset recorded at the Škoda factory.