Algorithmresearch
SuperPoint
Also called self-supervised interest point detection.
A network that detects points and computes descriptors in one pass, trained on its own detections warped by random homographies, called homographic adaptation.
- Solves
- Feature detection
- Time
- O(W H log(W H) + K r^2 + K C) worst · averageO(W H + K C) best
- Space
- O(W H + K C) extra
- Where
- C = the descriptor length; H = the image height; K = the number of kept points; W = the image width; r = the suppression radius
- Model
- Real RAM
- Properties
- deterministiclearnednetwork cost excludednot rotation invariantnot scale invariant
- Evidence
- Proof sketchCode in 1 languages
- Origin
- Daniel DeTone, Tomasz Malisiewicz, Andrew Rabinovich, 2018
SuperPoint is a convolutional network that takes a gray image and, in one forward pass, returns a score for each pixel of being an interest point and a descriptor for each point. A shared encoder reduces the image to cells of pixels. The detector head gives 65 values per cell, one for each of the 64 pixels and one for "no point here", and the descriptor head gives a coarse map of 256-value vectors. The network is trained by homographic adaptation: it detects points on many random homography warps of each training image and uses the merged detections as its own labels. This page covers the decoding step that turns the two outputs into keypoints and descriptors, with its proof and code; the network and its training are outside the page, and their quality is a measured result, not a theorem.
In plain words
The network looks at the image in small squares of 8 by 8 pixels. For each square it gives 65 numbers. Sixty-four of them say how likely each pixel of the square is to be a good point, and the last one says how likely it is that the square has no good point at all. A softmax turns the 65 numbers into chances that add up to 1. We throw away the "no point" chance and put the other 64 back in their pixels, which gives a score for every pixel of the image. Then we keep pixels with a high score, and among pixels that are close together we keep only the best one. For each kept pixel we read a vector from a second output of the network and scale it to length 1. Two views of the same spot should give close vectors.
The problem
The input is the output of the network for an image of pixels, with and :
- , an array of cells, each a vector of 65 logits . Channel belongs to the pixel at row and column of the cell. Channel 64 is the no-point bin, which the paper calls the dustbin.
- , an array of descriptor vectors of length , with in the paper.
- A score threshold , a suppression radius in pixels and a border width .
The output is a list of keypoints with scores, where is the column and the row, and one descriptor of Euclidean norm 1 for each keypoint. The keypoints are the pixels of the heat map that survive the threshold, the border and greedy non-maximum suppression.
The algorithm
SUPERPOINT-DECODE(X, F, τ, r, β)- 1
for each cell (c_x, c_y) of the H_c × W_c grid do - 2
p ← softmax of the 65 logits of X[c_y][c_x] - 3
for c = 0 to 63 do heat[8 c_y + ⌊c/8⌋][8 c_x + (c mod 8)] ← p_c ▷ p_64 is dropped - 4
P ← the pixels (u, v) with heat[v][u] ≥ τ and at least β pixels from each border - 5
sort P by decreasing score, ties by row and then by column - 6
K ← empty list; mark every pixel free - 7
for each pixel (u, v) of P in this order do - 8
if (u, v) is free then append (u, v) to K and mark the (2r + 1) × (2r + 1) square around it not free - 9
for each (u, v) in K do - 10
f ← bilinear sample of F at ((u - 3.5)/8, (v - 3.5)/8), clamped to the grid - 11
output (u, v, heat[v][u]) and f / ‖f‖
Lines L1 to L3 are the softmax and the reshape of Section 3.2 of the paper. The softmax is taken over all 65 channels, so a cell with a large dustbin value gives low scores to all its pixels; a cell can hold at most one strong point. Line L3 is the "depth to space" step: the 64 channels become an block of pixels. Lines L6 to L8 mark squares on a grid, so each test is ; this is the same greedy suppression as a test against every kept point. Line L10 is our choice of interpolation. The paper samples with bicubic interpolation and then normalizes; we use bilinear interpolation with the center of coarse cell at pixel . Other alignments of the coarse grid with the pixels are in use, and descriptors are comparable only under the same one.
The network before the decoder, from Section 3 of the paper: a VGG-style encoder with three max-pooling layers turns the image into an map. The detector head and the descriptor head are small convolutional layers on this map. The detector is trained with a cross-entropy loss over the 65 classes of each cell, and the descriptor with a hinge loss that pulls together the descriptors of cells that correspond under a known homography and pushes apart the others, with one margin for the positive pairs and one for the negative pairs.
Example
Take an image of pixels, so and . In cell 0 the logits are , , and 0 for the other 62 channels. The softmax denominator is . So , , the dustbin gets , and each other channel . Channel 27 is row and column , so pixel gets 0.3215. Channel 28 goes to with 0.1950.
In cell 1 only the dustbin is high, . Then , and each of the 64 pixels gets .
With and , line L4 keeps only and ; the values 0.0059 and 0.0021 are below the threshold. With both are kept. With or more, comes first, marks its square, and at Chebyshev distance 1 is suppressed. The output is one keypoint, with score 0.3215. Its descriptor is the bilinear sample of at , which the clamp moves to the center of cell 0, so it is divided by its norm.
Correctness
The decoder has a proof; the network does not. The proof in proofs/correctness.md shows:
- Per-cell probabilities. The 64 heat values of a cell are in and add up, with the dustbin, to 1. Adding a constant to the 65 logits of a cell does not change them.
- The reshape is a bijection. Each of the pixels gets exactly one channel of one cell.
- Greedy suppression. The grid marks of lines L6 to L8 give the same list as the test "no kept point within Chebyshev distance " in order of score. Kept points are more than apart, and each removed candidate is within of a kept point with a score at least its own.
- Descriptors. The bilinear sample is a convex combination of four map vectors, it is exact for a map that is affine in the cell index, and the output has norm 1.
What the network outputs is not proved to be good. The paper measures it. On HPatches (116 scenes, 696 images, 2018), with a correct-distance threshold of 3 pixels, SuperPoint did better than LIFT and ORB on homography estimation and was comparable to SIFT; the paper also reports repeatability against classical detectors. These are benchmark results with the protocol and the image size of the paper.
Proof: Correctness of the SuperPoint decoderfull
This proof covers the decoding step only: lines L1 to L11 of the main page, on given network outputs. The detector output has cells of 65 real logits, and the descriptor output has vectors in . Nothing here says that the network finds good points; that is a measured property.
Lemma 1 (the heat map is a probability per cell). For each cell , the 64 values that line L3 writes into the pixels , , are in , and their sum plus the dropped dustbin value is 1.
Proof. Line L2 computes with . Each term is positive and finite, so each is in when there are at least two channels, and . Subtracting multiplies the numerator and the denominator by the same factor , so equals the softmax .
Lemma 2 (each pixel gets exactly one channel). The map is a bijection from the channels of cell to the 64 pixels of that cell, and the cells partition the image.
Proof. Division with remainder writes each uniquely as with , and each pair comes from . The pixel is in exactly the cell . So line L3 writes each pixel exactly once.
Lemma 3 (invariance to a shift of the logits). Adding the same constant to the 65 logits of a cell does not change its heat values.
Proof. The softmax of has terms .
Let be the list of line L4 in the order of line L5: decreasing score, then increasing row, then increasing column. Write .
Lemma 4 (the grid test equals the distance test). When line L8 tests a pixel of , is marked "not free" if and only if some pixel kept before it is within Chebyshev distance of .
Proof. Line L6 starts with all pixels free. A pixel becomes not free only at line L8, when a kept pixel marks the square , clipped to the image. Pixels are never marked free again. So at the time of the test, is not free exactly when it is in the square of some earlier kept pixel, that is, within distance of it.
Theorem 1 (the result of NMS). Let be the list of kept pixels. Then:
- is the greedy list: a pixel of is in if and only if no pixel of that comes before it in the order of is within Chebyshev distance .
- Any two pixels of are at Chebyshev distance more than .
- Each pixel of that is not in is within distance of a pixel of whose score is at least its own.
- Each pixel of has score at least and lies at least pixels from each border.
Proof. Part 1 is Lemma 4 applied to each pixel in the order of line L7. For part 2, take in with before . When line L8 tested , it was free, so by Lemma 4 it was at distance more than from . For part 3, a pixel of that is not kept was not free at its test, so by Lemma 4 an earlier kept pixel is within distance . The order of line L5 puts before only if its score is at least the score of . Part 4 follows from line L4.
Lemma 5 (the descriptor). Let be the vector that line L10 computes for a pixel , with and clamped to . Then is a convex combination of the four vectors of around . If is an affine function of the cell index, , then exactly. If , line L11 returns a vector of Euclidean norm 1.
Proof. With , , and the same for , the weights , , and are non-negative and sum to 1. At the last column or row the code uses or , and then or because the clamp makes or an integer. For an affine , interpolation along gives , because an affine function is affine along each line, and the same holds along . Division by the norm gives a vector of norm 1.
Lemmas 1 to 5 together show that the decoder returns the greedy non-maximum suppression of the heat map defined by the per-cell softmax, with a unit descriptor for each kept pixel.
Complexity
The model is the real RAM, and the cost of the network is outside the page. Let .
- Lines L1 to L3 take time.
- Line L4 is and line L5 sorts at most candidates, . A threshold that keeps few pixels makes this small; a bucket sort on quantized scores makes it .
- Lines L6 to L8 take for the grid and for each kept point, so .
- Lines L9 to L11 take per kept point, in total.
The total is time and space. The paper reports about 11.15 ms for one forward pass of the network on a Titan X GPU for a image, and about 1.5 ms on a CPU for the descriptor sampling of 1000 points. These are measurements on the hardware of 2018.
Properties
- One pass for both tasks. Points and descriptors share the encoder, unlike a classical detector followed by a separate descriptor.
- At most one strong point per cell. The softmax over 65 channels makes the pixels of a cell compete, and the suppression removes the rest of the clusters.
- Pixel accuracy. The keypoints are pixel positions of the heat map. The decoder does not refine them to subpixel positions.
- Not rotation invariant. The network sees upright images with homographies of limited rotation during training. Large in-plane rotations lower the matching rate.
- No explicit scale. There is no scale space. Training warps include scale changes, so moderate scale changes work.
- Learned. The behavior depends on the training data and the weights. There is no invariance theorem as for SIFT.
Variants and improvements
- MagicPoint. The detector alone, trained on synthetic shapes with known corners, is the first stage of the training.
- Homographic adaptation. The paper warps each training image with about 100 random homographies, runs the detector on each, warps the heat maps back and averages them, and uses the result as the label. Repeating this improves the labels.
- Matchers on top. SuperGlue matches SuperPoint points with attention and optimal transport, and LightGlue is a later faster matcher. Classical matching with mutual nearest neighbors or the ratio test also works on its descriptors.
- Other learned features. LIFT, D2-Net, R2D2 and DISK are other learned detectors and descriptors. LoFTR drops the detector and matches dense coarse features.
When to use it
Use SuperPoint when you need repeatable points and good descriptors on images with strong changes of viewpoint or light, for example in visual localization or structure from motion, and a GPU is available. Pair it with SuperGlue or a ratio test and then RANSAC. Use ORB when there is no GPU and speed matters most, and SIFT when you need scale and rotation invariance with well understood behavior.
Pitfalls
- The image size. and must be multiples of 8, or the cells do not cover the image. Crop or pad first.
- The channel order. Channel is row and column of the cell. A different order in the reshape gives keypoints at wrong pixels that still look plausible.
- Softmax over 64 channels. Dropping the dustbin before the softmax removes the "no point" option, and every cell then has a pixel with a high score.
- Grid alignment. The descriptor map is 8 times coarser. Sample it with the alignment used in training; an offset of half a cell changes the descriptors.
- Normalize after sampling. Interpolation of unit vectors gives vectors shorter than 1. Normalize after line L10, as line L11 does.
- Border. Points near the border have poor descriptors. Remove them with before matching.
- Thresholds are tuned. , and are design choices. The paper evaluates suppression radii of 4 and 8 pixels on HPatches.
Implementations
The network is outside this page. The Python code in impl/python/superpoint.py implements only the decoder of lines L1 to L11 on network outputs that the tests build by hand or with a fixed seed: the per-cell softmax and reshape, the threshold and border, the grid suppression, and the bilinear sampling and normalization of the descriptors. The tests check that each cell sums to 1 with its dustbin, that each channel goes to its pixel, that the grid suppression equals a brute-force greedy suppression (with ties), that the kept points satisfy the properties of the theorem, and that the sampling is exact on an affine map.
Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/superpoint/. The authors are listed in prov/P2KH05.jsonl.
"""The decoding step of SuperPoint (DeTone, Malisiewicz and Rabinovich 2018).
The network is not part of this file. Its two outputs are given:
- X, the detector output: Hc rows of Wc cells, each a list of 65 logits.
Channels 0..63 are the 64 pixels of the 8 x 8 cell in row-major order,
channel c at row c // 8 and column c % 8 of the cell; channel 64 is the
"no interest point" bin (the dustbin).
- F, the coarse descriptor map: Hc rows of Wc vectors of the same length.
The image has H = 8 Hc rows and W = 8 Wc columns. A pixel is (u, v), with u
the column and v the row; heat[v][u] is its score.
The decoder takes a softmax over the 65 channels of each cell, drops the
dustbin and places the 64 values in the cell (the "depth to space" step).
Then it keeps the pixels with score at least tau that are not too close to the
border, and runs greedy non-maximum suppression: in order of decreasing score,
a pixel is kept if no kept pixel is within Chebyshev distance r.
The descriptor of a kept pixel is sampled from F by bilinear interpolation
and divided by its Euclidean norm. The paper uses bicubic interpolation; this
code uses bilinear interpolation, with the center of coarse cell (cx, cy) at
pixel (8 cx + 3.5, 8 cy + 3.5). The alignment is a convention.
"""
import math
from typing import List, Sequence, Tuple
CELL = 8
def softmax(z: Sequence[float]) -> List[float]:
m = max(z)
e = [math.exp(x - m) for x in z]
s = sum(e)
return [x / s for x in e]
def decode_heatmap(X: Sequence[Sequence[Sequence[float]]]) -> List[List[float]]:
"""Turn Hc x Wc cells of 65 logits into an H x W heat map."""
hc, wc = len(X), len(X[0])
heat = [[0.0] * (CELL * wc) for _ in range(CELL * hc)]
for cy in range(hc): # @line L1
for cx in range(wc):
logits = X[cy][cx]
if len(logits) != CELL * CELL + 1:
raise ValueError("each cell needs 65 logits")
p = softmax(logits) # @line L2
for c in range(CELL * CELL): # @line L3
heat[CELL * cy + c // CELL][CELL * cx + c % CELL] = p[c]
return heat
def nms(heat: Sequence[Sequence[float]], tau: float, r: int, border: int) -> List[Tuple[int, int, float]]:
"""Greedy grid NMS. Return the kept (u, v, score), by decreasing score."""
h, w = len(heat), len(heat[0])
cand = [(heat[v][u], u, v) # @line L4
for v in range(border, h - border) for u in range(border, w - border)
if heat[v][u] >= tau]
cand.sort(key=lambda t: (-t[0], t[2], t[1])) # @line L5
free = [[True] * w for _ in range(h)] # @line L6
kept = []
for s, u, v in cand: # @line L7
if free[v][u]: # @line L8
kept.append((u, v, s))
for y in range(max(0, v - r), min(h, v + r + 1)):
row = free[y]
for x in range(max(0, u - r), min(w, u + r + 1)):
row[x] = False
return kept
def sample_descriptor(F: Sequence[Sequence[Sequence[float]]], u: float, v: float,
normalize: bool = True) -> List[float]:
"""Bilinear sample of the coarse map F at pixel (u, v), then L2 normalization."""
hc, wc = len(F), len(F[0])
fx = min(max((u - 3.5) / CELL, 0.0), wc - 1.0) # @line L10
fy = min(max((v - 3.5) / CELL, 0.0), hc - 1.0)
x0, y0 = int(math.floor(fx)), int(math.floor(fy))
x1, y1 = min(x0 + 1, wc - 1), min(y0 + 1, hc - 1)
ax, ay = fx - x0, fy - y0
f = [(1 - ax) * (1 - ay) * a + ax * (1 - ay) * b + (1 - ax) * ay * c + ax * ay * d
for a, b, c, d in zip(F[y0][x0], F[y0][x1], F[y1][x0], F[y1][x1])]
if not normalize:
return f
n = math.sqrt(sum(t * t for t in f)) # @line L11
return [t / n for t in f] if n > 0 else f
def superpoint_decode(X, F, tau: float = 0.015, r: int = 4, border: int = 4):
"""Return (keypoints, descriptors): keypoints as (u, v, score), descriptors of unit norm."""
heat = decode_heatmap(X)
kept = nms(heat, tau, r, border)
desc = [sample_descriptor(F, u, v) for u, v, _ in kept] # @line L9
return kept, desc
test_superpoint.py 119 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/superpoint/. The authors are listed in prov/P2KH05.jsonl.
import math
import random
import pytest
from superpoint import decode_heatmap, nms, sample_descriptor, softmax, superpoint_decode
def random_logits(rng, hc, wc, spread=3.0):
return [[[rng.gauss(0.0, spread) for _ in range(65)] for _ in range(wc)] for _ in range(hc)]
def brute_nms(heat, tau, r, border):
"""Greedy NMS by its definition, in O(n^2): keep a pixel if no kept pixel is within r."""
h, w = len(heat), len(heat[0])
cand = [(heat[v][u], u, v) for v in range(h) for u in range(w)
if heat[v][u] >= tau and border <= u < w - border and border <= v < h - border]
cand.sort(key=lambda t: (-t[0], t[2], t[1]))
kept = []
for s, u, v in cand:
if all(max(abs(u - a), abs(v - b)) > r for a, b, _ in kept):
kept.append((u, v, s))
return kept
def test_cell_probabilities_with_dustbin_sum_to_one():
rng = random.Random(1)
X = random_logits(rng, 3, 4)
heat = decode_heatmap(X)
assert len(heat) == 24 and len(heat[0]) == 32
for cy in range(3):
for cx in range(4):
cell = sum(heat[8 * cy + i][8 * cx + j] for i in range(8) for j in range(8))
dust = softmax(X[cy][cx])[64]
assert abs(cell + dust - 1.0) < 1e-12
assert all(0.0 < heat[8 * cy + i][8 * cx + j] < 1.0 for i in range(8) for j in range(8))
def test_channel_goes_to_its_pixel():
for cy, cx, c in ((0, 0, 0), (1, 2, 27), (2, 1, 63), (0, 3, 8)):
X = [[[0.0] * 65 for _ in range(4)] for _ in range(3)]
X[cy][cx][c] = 20.0
heat = decode_heatmap(X)
best = max((heat[v][u], u, v) for v in range(24) for u in range(32))
assert (best[1], best[2]) == (8 * cx + c % 8, 8 * cy + c // 8)
def test_shift_of_logits_and_large_values():
rng = random.Random(2)
X = random_logits(rng, 2, 2)
Y = [[[x + 1000.0 for x in cell] for cell in row] for row in X]
a, b = decode_heatmap(X), decode_heatmap(Y)
assert all(abs(p - q) < 1e-12 for ra, rb in zip(a, b) for p, q in zip(ra, rb))
with pytest.raises(ValueError):
decode_heatmap([[[0.0] * 64]])
def test_nms_equals_brute_force_definition():
rng = random.Random(3)
for trial in range(12):
X = random_logits(rng, 3, 3, spread=rng.choice((1.0, 3.0, 6.0)))
heat = decode_heatmap(X)
if trial % 3 == 0: # create exact ties
heat = [[round(x, 2) for x in row] for row in heat]
for r in (0, 1, 2, 4):
for border in (0, 2):
tau = rng.choice((0.0, 0.01, 0.05))
assert nms(heat, tau, r, border) == brute_nms(heat, tau, r, border)
def test_many_small_heat_maps_against_brute_force():
rng = random.Random(6)
for _ in range(600):
h, w = rng.randint(1, 9), rng.randint(1, 9)
heat = [[rng.choice((0.0, 0.1, 0.2, 0.3, rng.random())) for _ in range(w)] for _ in range(h)]
r, border = rng.randint(0, 3), rng.randint(0, 2)
tau = rng.choice((0.0, 0.1, 0.25))
assert nms(heat, tau, r, border) == brute_nms(heat, tau, r, border)
def test_nms_output_properties():
rng = random.Random(4)
heat = decode_heatmap(random_logits(rng, 4, 4, 4.0))
r, tau = 3, 0.02
kept = nms(heat, tau, r, 0)
for i, (u, v, s) in enumerate(kept):
for a, b, t in kept[i + 1:]:
assert max(abs(u - a), abs(v - b)) > r and t <= s
keep_set = {(u, v) for u, v, _ in kept}
for v in range(32):
for u in range(32):
if heat[v][u] >= tau and (u, v) not in keep_set:
assert any(max(abs(u - a), abs(v - b)) <= r and s >= heat[v][u] for a, b, s in kept)
def test_bilinear_sampling_reproduces_an_affine_map():
hc, wc = 3, 4
F = [[[2.0 * cx - cy + 1.0, 0.5 * cy, 3.0] for cx in range(wc)] for cy in range(hc)]
for u, v in ((3.5, 3.5), (10.0, 7.0), (20.25, 12.5), (27.5, 19.5)):
fx, fy = (u - 3.5) / 8, (v - 3.5) / 8
got = sample_descriptor(F, u, v, normalize=False)
want = [2.0 * fx - fy + 1.0, 0.5 * fy, 3.0]
assert all(abs(g - w) < 1e-12 for g, w in zip(got, want))
# outside the centers the sample is clamped to the border cells
assert sample_descriptor(F, 0.0, 0.0, normalize=False) == F[0][0]
def test_full_decode_gives_unit_descriptors():
rng = random.Random(5)
X = random_logits(rng, 4, 5, 3.0)
F = [[[rng.gauss(0, 1) for _ in range(16)] for _ in range(5)] for _ in range(4)]
kps, desc = superpoint_decode(X, F, tau=0.01, r=2, border=4)
assert len(kps) == len(desc) > 0
for (u, v, s), f in zip(kps, desc):
assert 4 <= u < 36 and 4 <= v < 28 and s >= 0.01
assert abs(math.sqrt(sum(t * t for t in f)) - 1.0) < 1e-12
History
Learned interest points before SuperPoint, such as LIFT (2016), used separate networks for detection, orientation and description, trained with points from a classical pipeline. DeTone, Malisiewicz and Rabinovich (2018) trained one network for both tasks without human labels: a detector trained on synthetic shapes labels real images through homographic adaptation, and the full network learns from those labels. In 2020 Sarlin and the same group added SuperGlue on top, and the pair became a common baseline for learned matching.
References
- Daniel DeTone, Tomasz Malisiewicz and Andrew Rabinovich, SuperPoint, self-supervised interest point detection and description, IEEE/CVF Conference on Computer Vision and Pattern Recognition Workshops (CVPRW), 2018 (arXiv 1712.07629), Section 3.1 (the shared encoder with cells of 8 x 8 pixels), Section 3.2 (the 65-channel detector head, the softmax and the reshape), Section 3.3 (the descriptor head, the interpolation and the L2 normalization), the sections on the losses, on homographic adaptation and on the HPatches experiments
- Paul-Edouard Sarlin, Daniel DeTone, Tomasz Malisiewicz and Andrew Rabinovich, SuperGlue, learning feature matching with graph neural networks, IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR), 2020 (arXiv 1911.11763), the experiments that use SuperPoint keypoints and descriptors as the input of the matcher
- Jiaming Sun, Zehong Shen, Yuang Wang, Hujun Bao and Xiaowei Zhou, LoFTR, detector-free local feature matching with transformers, IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR), 2021 (arXiv 2104.00680), the comparison with SuperPoint and SuperGlue as a detector-based baseline
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H1 sketch |
|
| Lean | L0 no Lean part |
|
| Code (python) | I0 not checked yet |
|
| Visual | V0 none |
|
| Writing | W2 basic |
|
Tag P2KH05 Edit this page History Report an error Markdown