Algorithm Search⌘K

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.

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
Properties
deterministiclearnednetwork cost excludednot rotation invariantnot scale invariant
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 8×88 \times 8 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 H×WH \times W pixels, with H=8HcH = 8 H_c and W=8WcW = 8 W_c:

  • XX, an array of Hc×WcH_c \times W_c cells, each a vector of 65 logits z0,…,z64z_0, \dots, z_{64}. Channel c<64c < 64 belongs to the pixel at row ⌊c/8⌋\lfloor c/8 \rfloor and column c mod 8c \bmod 8 of the cell. Channel 64 is the no-point bin, which the paper calls the dustbin.
  • FF, an array of Hc×WcH_c \times W_c descriptor vectors of length CC, with C=256C = 256 in the paper.
  • A score threshold τ\tau, a suppression radius rr in pixels and a border width β\beta.

The output is a list of keypoints (u,v)(u, v) with scores, where uu is the column and vv 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

  1. SUPERPOINT-DECODE(X, F, τ, r, β)
  2. 1for each cell (c_x, c_y) of the H_c × W_c grid do
  3. 2p ← softmax of the 65 logits of X[c_y][c_x]
  4. 3for c = 0 to 63 do heat[8 c_y + ⌊c/8⌋][8 c_x + (c mod 8)] ← p_c ▷ p_64 is dropped
  5. 4P ← the pixels (u, v) with heat[v][u] ≥ τ and at least β pixels from each border
  6. 5sort P by decreasing score, ties by row and then by column
  7. 6K ← empty list; mark every pixel free
  8. 7for each pixel (u, v) of P in this order do
  9. 8if (u, v) is free then append (u, v) to K and mark the (2r + 1) × (2r + 1) square around it not free
  10. 9for each (u, v) in K do
  11. 10f ← bilinear sample of F at ((u - 3.5)/8, (v - 3.5)/8), clamped to the grid
  12. 11output (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 8×88 \times 8 block of pixels. Lines L6 to L8 mark squares on a grid, so each test is O(1)O(1); this is the same greedy suppression as a test against every kept point. Line L10 is our choice of interpolation. The paper samples FF with bicubic interpolation and then normalizes; we use bilinear interpolation with the center of coarse cell (cx,cy)(c_x, c_y) at pixel (8cx+3.5,8cy+3.5)(8 c_x + 3.5, 8 c_y + 3.5). 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 H×WH \times W image into an Hc×WcH_c \times W_c 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 8×168 \times 16 pixels, so Hc=1H_c = 1 and Wc=2W_c = 2. In cell 0 the logits are z27=4z_{27} = 4, z28=3.5z_{28} = 3.5, z64=3z_{64} = 3 and 0 for the other 62 channels. The softmax denominator is e4+e3.5+e3+62=54.598+33.115+20.086+62=169.80e^4 + e^{3.5} + e^3 + 62 = 54.598 + 33.115 + 20.086 + 62 = 169.80. So p27=0.3215p_{27} = 0.3215, p28=0.1950p_{28} = 0.1950, the dustbin gets 0.11830.1183, and each other channel 1/169.80=0.00591/169.80 = 0.0059. Channel 27 is row ⌊27/8⌋=3\lfloor 27/8 \rfloor = 3 and column 27 mod 8=327 \bmod 8 = 3, so pixel (u,v)=(3,3)(u, v) = (3, 3) gets 0.3215. Channel 28 goes to (4,3)(4, 3) with 0.1950.

In cell 1 only the dustbin is high, z64=6z_{64} = 6. Then p64=e6/(e6+64)=403.43/467.43=0.8631p_{64} = e^6 / (e^6 + 64) = 403.43 / 467.43 = 0.8631, and each of the 64 pixels gets 1/467.43=0.00211/467.43 = 0.0021.

With τ=0.015\tau = 0.015 and β=0\beta = 0, line L4 keeps only (3,3)(3, 3) and (4,3)(4, 3); the values 0.0059 and 0.0021 are below the threshold. With r=0r = 0 both are kept. With r=1r = 1 or more, (3,3)(3, 3) comes first, marks its square, and (4,3)(4, 3) at Chebyshev distance 1 is suppressed. The output is one keypoint, (3,3)(3, 3) with score 0.3215. Its descriptor is the bilinear sample of FF at ((3−3.5)/8,(3−3.5)/8)=(−0.0625,−0.0625)((3 - 3.5)/8, (3 - 3.5)/8) = (-0.0625, -0.0625), which the clamp moves to the center of cell 0, so it is F[0][0]F[0][0] 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 (0,1)(0, 1) 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 HWH W 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 rr" in order of score. Kept points are more than rr apart, and each removed candidate is within rr 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 XX has Hc×WcH_c \times W_c cells of 65 real logits, and the descriptor output FF has Hc×WcH_c \times W_c vectors in Rm\mathbb{R}^{m}. 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 (cx,cy)(c_x, c_y), the 64 values that line L3 writes into the pixels (8cx+a,8cy+b)(8 c_x + a, 8 c_y + b), 0≤a,b≤70 \le a, b \le 7, are in (0,1)(0, 1), and their sum plus the dropped dustbin value p64p_{64} is 1.

Proof. Line L2 computes pc=ezc−M/∑c′ezc′−Mp_c = e^{z_c - M} / \sum_{c'} e^{z_{c'} - M} with M=max⁡czcM = \max_c z_c. Each term ezc−Me^{z_c - M} is positive and finite, so each pcp_c is in (0,1)(0, 1) when there are at least two channels, and ∑c=064pc=1\sum_{c=0}^{64} p_c = 1. Subtracting MM multiplies the numerator and the denominator by the same factor e−Me^{-M}, so pcp_c equals the softmax ezc/∑ezc′e^{z_c} / \sum e^{z_{c'}}. □\square

Lemma 2 (each pixel gets exactly one channel). The map c↦(8cx+(c mod 8),8cy+⌊c/8⌋)c \mapsto (8 c_x + (c \bmod 8), 8 c_y + \lfloor c / 8 \rfloor) is a bijection from the channels 0,…,630, \dots, 63 of cell (cx,cy)(c_x, c_y) to the 64 pixels of that cell, and the cells partition the 8Hc×8Wc8 H_c \times 8 W_c image.

Proof. Division with remainder writes each c∈{0,…,63}c \in \{0, \dots, 63\} uniquely as c=8b+ac = 8 b + a with 0≤a,b≤70 \le a, b \le 7, and each pair (a,b)(a, b) comes from c=8b+ac = 8 b + a. The pixel (u,v)(u, v) is in exactly the cell (⌊u/8⌋,⌊v/8⌋)(\lfloor u/8 \rfloor, \lfloor v/8 \rfloor). So line L3 writes each pixel exactly once. □\square

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 z+t1z + t \mathbf{1} has terms ezc+t/∑ezc′+t=ezc/∑ezc′e^{z_c + t} / \sum e^{z_{c'} + t} = e^{z_c} / \sum e^{z_{c'}}. □\square

Let CC be the list of line L4 in the order of line L5: decreasing score, then increasing row, then increasing column. Write ∥(u,v)−(u′,v′)∥∞=max⁡(∣u−u′∣,∣v−v′∣)\lVert (u, v) - (u', v') \rVert_\infty = \max(|u - u'|, |v - v'|).

Lemma 4 (the grid test equals the distance test). When line L8 tests a pixel pp of CC, pp is marked "not free" if and only if some pixel kept before it is within Chebyshev distance rr of pp.

Proof. Line L6 starts with all pixels free. A pixel becomes not free only at line L8, when a kept pixel kk marks the square {p:∥p−k∥∞≤r}\{p : \lVert p - k \rVert_\infty \le r\}, clipped to the image. Pixels are never marked free again. So at the time of the test, pp is not free exactly when it is in the square of some earlier kept pixel, that is, within distance rr of it. □\square

Theorem 1 (the result of NMS). Let KK be the list of kept pixels. Then:

  1. KK is the greedy list: a pixel of CC is in KK if and only if no pixel of KK that comes before it in the order of CC is within Chebyshev distance rr.
  2. Any two pixels of KK are at Chebyshev distance more than rr.
  3. Each pixel of CC that is not in KK is within distance rr of a pixel of KK whose score is at least its own.
  4. Each pixel of KK has score at least τ\tau and lies at least β\beta pixels from each border.

Proof. Part 1 is Lemma 4 applied to each pixel in the order of line L7. For part 2, take k,k′k, k' in KK with kk before k′k'. When line L8 tested k′k', it was free, so by Lemma 4 it was at distance more than rr from kk. For part 3, a pixel pp of CC that is not kept was not free at its test, so by Lemma 4 an earlier kept pixel kk is within distance rr. The order of line L5 puts kk before pp only if its score is at least the score of pp. Part 4 follows from line L4. □\square

Lemma 5 (the descriptor). Let ff be the vector that line L10 computes for a pixel (u,v)(u, v), with fx=(u−3.5)/8f_x = (u - 3.5)/8 and fy=(v−3.5)/8f_y = (v - 3.5)/8 clamped to [0,Wc−1]×[0,Hc−1][0, W_c - 1] \times [0, H_c - 1]. Then ff is a convex combination of the four vectors of FF around (fx,fy)(f_x, f_y). If FF is an affine function of the cell index, F[cy][cx]=A(cx,cy)T+bF[c_y][c_x] = A (c_x, c_y)^T + b, then f=A(fx,fy)T+bf = A (f_x, f_y)^T + b exactly. If f≠0f \ne 0, line L11 returns a vector of Euclidean norm 1.

Proof. With x0=⌊fx⌋x_0 = \lfloor f_x \rfloor, α=fx−x0∈[0,1)\alpha = f_x - x_0 \in [0, 1), and y0,β′y_0, \beta' the same for fyf_y, the weights (1−α)(1−β′)(1-\alpha)(1-\beta'), α(1−β′)\alpha(1-\beta'), (1−α)β′(1-\alpha)\beta' and αβ′\alpha\beta' are non-negative and sum to 1. At the last column or row the code uses x1=x0x_1 = x_0 or y1=y0y_1 = y_0, and then α=0\alpha = 0 or β′=0\beta' = 0 because the clamp makes fx=Wc−1f_x = W_c - 1 or fy=Hc−1f_y = H_c - 1 an integer. For an affine FF, interpolation along xx gives (1−α)F[⋅][x0]+αF[⋅][x0+1]=A(x0+α,⋅)T+b(1 - \alpha) F[\cdot][x_0] + \alpha F[\cdot][x_0 + 1] = A (x_0 + \alpha, \cdot)^T + b, because an affine function is affine along each line, and the same holds along yy. Division by the norm ∥f∥>0\lVert f \rVert > 0 gives a vector of norm 1. □\square

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. ■\blacksquare

Complexity

The model is the real RAM, and the cost of the network is outside the page. Let n=WHn = W H.

  • Lines L1 to L3 take O(65HcWc)=O(n)O(65 H_c W_c) = O(n) time.
  • Line L4 is O(n)O(n) and line L5 sorts at most nn candidates, O(nlog⁡n)O(n \log n). A threshold that keeps few pixels makes this small; a bucket sort on quantized scores makes it O(n)O(n).
  • Lines L6 to L8 take O(n)O(n) for the grid and O(r2)O(r^2) for each kept point, so O(n+Kr2)O(n + K r^2).
  • Lines L9 to L11 take O(C)O(C) per kept point, O(KC)O(K C) in total.

The total is O(nlog⁡n+Kr2+KC)O(n \log n + K r^2 + K C) time and O(n+KC)O(n + K C) space. The paper reports about 11.15 ms for one forward pass of the network on a Titan X GPU for a 480×640480 \times 640 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. HH and WW must be multiples of 8, or the cells do not cover the image. Crop or pad first.
  • The channel order. Channel cc is row ⌊c/8⌋\lfloor c/8 \rfloor and column c mod 8c \bmod 8 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 β\beta before matching.
  • Thresholds are tuned. τ\tau, rr and β\beta 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.

superpoint.pyI0RawGitHub
# 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

  1. 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
  2. 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
  3. 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.

LadderLevelWhat the next level needs
Human proofH1 sketch
  • a full proof of time.average
  • a full proof of time.best
  • a full proof of time.worst
  • a full proof of space.extra
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
Code (python)I0 not checked yet
  • the tests did not run in this build
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW2 basic
  • a scene preset for the example