Algorithm Search⌘K

Algorithmadvanced

VLAD

Also called vector of locally aggregated descriptors.

Represent an image by summing, for each visual word, the residuals of the descriptors assigned to it, then normalizing the concatenated vector.

Time
O(n K D) worst · best
Space
O(K D) extra
Where
D = the descriptor dimension; K = the number of centers; n = the number of local descriptors of the image
Properties
deterministicexactorder invariant
Origin
Herve Jegou, Matthijs Douze, Cordelia Schmid, Patrick Perez, 2010

VLAD (vector of locally aggregated descriptors) turns the set of local descriptors of an image into one vector of fixed length. Each descriptor is assigned to its nearest center of a small codebook, as in the bag of visual words, but instead of counting, VLAD adds up the residuals x−ckx - c_k, the vectors from the center to the descriptors. The KK sums of dimension DD are concatenated and normalized, so two images can be compared by one inner product. VLAD is a simplified Fisher vector: hard assignment and the first-order statistics only.

In plain words

Pick a small set of typical patch descriptors, the centers. For each patch of an image, find its closest center and write down the difference between the patch and that center. Add up the differences that belong to the same center. The result is one short list of numbers for each center, and together these lists describe the image.

A count only says how many patches are near a center. The sum of differences also says in which direction they lie from it. So a few dozen centers already give a detailed description, and the whole image fits in one vector that a computer can compare fast and compress.

The problem

Input. A codebook C=(c1,…,cK)C = (c_1, \ldots, c_K) of KK centers in RD\mathbb{R}^D, usually from k-means on training descriptors, and the nn local descriptors X={x1,…,xn}⊂RDX = \{x_1, \ldots, x_n\} \subset \mathbb{R}^D of one image (for example SIFT with D=128D = 128, or RootSIFT). Optional parameters: the power α∈(0,1]\alpha \in (0, 1] and a flag for intra-normalization.

Output. A vector z∈RKDz \in \mathbb{R}^{K D}. The nearest center is NN(x)=arg⁡min⁡k∥x−ck∥2\mathrm{NN}(x) = \arg\min_k \lVert x - c_k \rVert_2 with ties to the smaller index. Before normalization, block kk of zz is

vk=∑x∈X, NN(x)=k(x−ck).v_k = \sum_{x \in X,\ \mathrm{NN}(x) = k} (x - c_k).

Images are compared by ⟨zq,zd⟩\langle z_q, z_d \rangle, or by the Euclidean distance, which gives the same ranking for unit vectors.

The algorithm

  1. VLAD(X, C, alpha, intra) ▷ K = |C|, each c_k in R^D
  2. 1v_k ← 0 in R^D for k = 1..K
  3. 2for each descriptor x in X do
  4. 3k ← index of the nearest center to x, ties to the smaller index
  5. 4v_k ← v_k + (x - c_k)
  6. 5if intra then v_k ← v_k / ||v_k|| for each k with v_k ≠ 0
  7. 6z ← (v_1, ..., v_K), the concatenation of the blocks
  8. 7if alpha < 1 then z_i ← sign(z_i) |z_i|^alpha for each i
  9. 8if z ≠ 0 then z ← z / ||z||
  10. 9return z

Lines L1 to L4 are the aggregation of Jegou et al. (2010). Line L7 is the power normalization of the journal version, with α=0.5\alpha = 0.5 as the usual choice (the signed square root). Line L5 is the intra-normalization of Arandjelovic and Zisserman (2013), which they use against bursty features. Line L8 is always applied.

Example

Take D=2D = 2, K=2K = 2, c1=(0,0)c_1 = (0, 0), c2=(4,0)c_2 = (4, 0), and five descriptors (1,1)(1, 1), (−1,2)(-1, 2), (3,1)(3, 1), (5,−1)(5, -1), (6,0)(6, 0).

xx squared distance to c1c_1, c2c_2 cell residual
(1,1)(1, 1) 2, 10 1 (1,1)(1, 1)
(−1,2)(-1, 2) 5, 29 1 (−1,2)(-1, 2)
(3,1)(3, 1) 10, 2 2 (−1,1)(-1, 1)
(5,−1)(5, -1) 26, 2 2 (1,−1)(1, -1)
(6,0)(6, 0) 36, 4 2 (2,0)(2, 0)

The blocks are v1=(0,3)v_1 = (0, 3) and v2=(2,0)v_2 = (2, 0), so z=(0,3,2,0)z = (0, 3, 2, 0) before line L8, and z=(0,3,2,0)/13=(0,0.8321,0.5547,0)z = (0, 3, 2, 0)/\sqrt{13} = (0, 0.8321, 0.5547, 0) after it. With α=0.5\alpha = 0.5, line L7 gives (0,3,2,0)(0, \sqrt 3, \sqrt 2, 0) and line L8 gives (0,0.7746,0.6325,0)(0, 0.7746, 0.6325, 0). With intra-normalization, line L5 gives v1=(0,1)v_1 = (0, 1) and v2=(1,0)v_2 = (1, 0), and the result is (0,0.7071,0.7071,0)(0, 0.7071, 0.7071, 0): both cells now weigh the same, whatever their counts.

The residuals (−1,1)(-1, 1) and (1,−1)(1, -1) in cell 2 cancel. Two descriptors on opposite sides of a center leave no trace in its block. The tests check all these numbers.

Correctness

The proof in the correctness file shows four facts. First, each descriptor adds its residual to exactly one block in line L4, so the result does not depend on the order of XX, and vk=nk(xˉk−ck)v_k = n_k (\bar x_k - c_k), where nkn_k is the number of descriptors in cell kk and xˉk\bar x_k is their mean. Second, for two images without normalization,

⟨v(X),v(Y)⟩=∑k=1K∑x∈Xk∑y∈Yk⟨x−ck,y−ck⟩,\langle v(X), v(Y) \rangle = \sum_{k=1}^{K} \sum_{x \in X_k} \sum_{y \in Y_k} \langle x - c_k, y - c_k \rangle,

so VLAD is the explicit feature map of a match kernel that compares only descriptors in the same cell, and the inner product costs O(KD)O(K D) instead of O(nmD)O(n m D) for mm descriptors in the second image. Third, this kernel is positive semidefinite, since it is an inner product of feature vectors. Fourth, if a Fisher vector uses a mixture with weights wk=1/Kw_k = 1/K, unit variances, means ckc_k and hard assignment, its gradient with respect to the means is (K/n) v(\sqrt{K}/n)\, v, so after L2 normalization the two vectors are equal (Sanchez et al. 2013, Section 2.5).

Proof: VLAD is an order-invariant feature map of the same-cell residual match kernel and a scaled hard-assignment Fisher vectorfull

We use the notation of the page. The codebook is c1,…,cK∈RDc_1, \ldots, c_K \in \mathbb{R}^D. For a descriptor xx, NN(x)\mathrm{NN}(x) is the smallest index kk that minimizes ∥x−ck∥2\lVert x - c_k \rVert_2. For a finite multiset XX of descriptors, Xk={x∈X:NN(x)=k}X_k = \{x \in X : \mathrm{NN}(x) = k\}, nk=∣Xk∣n_k = |X_k|, and vk(X)v_k(X) is block kk after lines L1 to L4 of VLAD. We write v(X)v(X) for the concatenation of the blocks, before lines L5 to L8.

Lemma 1 (what the loop computes). After lines L1 to L4, vk(X)=∑x∈Xk(x−ck)v_k(X) = \sum_{x \in X_k} (x - c_k) for every kk.

Proof. Line L1 sets every block to 0. Each pass of the loop of line L2 handles one descriptor xx. Line L3 computes k=NN(x)k = \mathrm{NN}(x), and line L4 adds x−ckx - c_k to block kk and to no other block. By induction on the number of passes, after the descriptors x1,…,xjx_1, \ldots, x_j have been handled, block kk is the sum of xi−ckx_i - c_k over the i≤ji \le j with NN(xi)=k\mathrm{NN}(x_i) = k. With j=nj = n this is the claim. □\square

Corollary 1 (order invariance and the mean form). The output does not depend on the order in which line L2 visits XX. If nk>0n_k > 0 and xˉk\bar x_k is the mean of XkX_k, then vk(X)=nk(xˉk−ck)v_k(X) = n_k (\bar x_k - c_k); if nk=0n_k = 0, then vk(X)=0v_k(X) = 0.

Proof. The right side of Lemma 1 is a sum over a set that is defined without an order, and addition in RD\mathbb{R}^D is commutative and associative. Lines L5 to L8 are functions of the blocks only. For the mean form, ∑x∈Xk(x−ck)=∑x∈Xkx−nkck=nkxˉk−nkck\sum_{x \in X_k} (x - c_k) = \sum_{x \in X_k} x - n_k c_k = n_k \bar x_k - n_k c_k. □\square

In floating point the sum can differ in the last bits for another order. The claim is about the exact values.

Lemma 2 (additivity). If XX and YY are multisets and X⊎YX \uplus Y is their union with multiplicities, then v(X⊎Y)=v(X)+v(Y)v(X \uplus Y) = v(X) + v(Y).

Proof. NN\mathrm{NN} depends only on the descriptor, so (X⊎Y)k=Xk⊎Yk(X \uplus Y)_k = X_k \uplus Y_k, and the sum of Lemma 1 splits. □\square

Theorem 1 (match kernel). For two multisets XX and YY,

⟨v(X),v(Y)⟩=∑k=1K∑x∈Xk∑y∈Yk⟨x−ck,y−ck⟩.\langle v(X), v(Y) \rangle = \sum_{k=1}^{K} \sum_{x \in X_k} \sum_{y \in Y_k} \langle x - c_k, y - c_k \rangle.

Hence the function kVLAD(X,Y)=⟨v(X),v(Y)⟩k_{\mathrm{VLAD}}(X, Y) = \langle v(X), v(Y) \rangle on finite multisets is a positive semidefinite kernel.

Proof. The inner product of two concatenations is the sum of the inner products of the blocks: ⟨v(X),v(Y)⟩=∑k⟨vk(X),vk(Y)⟩\langle v(X), v(Y) \rangle = \sum_k \langle v_k(X), v_k(Y) \rangle. By Lemma 1 and the bilinearity of the inner product,

⟨vk(X),vk(Y)⟩=⟨∑x∈Xk(x−ck),∑y∈Yk(y−ck)⟩=∑x∈Xk∑y∈Yk⟨x−ck,y−ck⟩.\langle v_k(X), v_k(Y) \rangle = \Big\langle \sum_{x \in X_k} (x - c_k), \sum_{y \in Y_k} (y - c_k) \Big\rangle = \sum_{x \in X_k} \sum_{y \in Y_k} \langle x - c_k, y - c_k \rangle.

Summing over kk gives the identity. For the second claim, take multisets X(1),…,X(m)X^{(1)}, \ldots, X^{(m)} and reals a1,…,ama_1, \ldots, a_m. Then ∑i,jaiajkVLAD(X(i),X(j))=∥∑iaiv(X(i))∥2≥0\sum_{i,j} a_i a_j k_{\mathrm{VLAD}}(X^{(i)}, X^{(j)}) = \lVert \sum_i a_i v(X^{(i)}) \rVert^2 \ge 0. □\square

The normalized versions are also positive semidefinite: if z(X)=f(v(X))z(X) = f(v(X)) for any map ff into RKD\mathbb{R}^{KD}, then ⟨z(X),z(Y)⟩\langle z(X), z(Y) \rangle is again an inner product of feature vectors, and the same argument applies. This covers lines L5, L7 and L8.

Lemma 3 (normalization). If the output zz of line L9 is not zero, then ∥z∥2=1\lVert z \rVert_2 = 1. If line L5 runs, every block of the vector before line L7 has norm 1 or is zero. Line L7 keeps the sign of each entry and keeps zero entries at zero, so it does not change which entries are zero.

Proof. Line L8 divides a nonzero vector by its norm. Line L5 divides each nonzero block by its norm and leaves zero blocks. For line L7, sign(t)∣t∣α\mathrm{sign}(t)|t|^\alpha is zero exactly when t=0t = 0 and has the sign of tt otherwise, since ∣t∣α>0|t|^\alpha > 0 for t≠0t \ne 0. So if z≠0z \ne 0 before line L7, it is still nonzero after it, and line L8 applies. □\square

Theorem 2 (VLAD as a Fisher vector). Take a Gaussian mixture with KK components, weights wk=1/Kw_k = 1/K, means μk=ck\mu_k = c_k and identity covariances, and replace its posteriors by the hard assignment γx(k)=1\gamma_x(k) = 1 if NN(x)=k\mathrm{NN}(x) = k and 0 otherwise. The normalized gradient with respect to the means of the Fisher vector of a set XX of n≥1n \ge 1 descriptors, Gμk=1nwk∑x∈Xγx(k)x−μkσk\mathcal{G}_{\mu_k} = \frac{1}{n\sqrt{w_k}} \sum_{x \in X} \gamma_x(k) \frac{x - \mu_k}{\sigma_k} (Sanchez et al. 2013, Eq. 17, divided by the number of descriptors), satisfies Gμ=Knv(X)\mathcal{G}_\mu = \frac{\sqrt{K}}{n} v(X). So, when v(X)≠0v(X) \ne 0, the L2-normalized Fisher mean gradient equals the VLAD vector of lines L1 to L4 and L8.

Proof. With σk=1\sigma_k = 1 and wk=1/Kw_k = 1/K, 1nwk=Kn\frac{1}{n \sqrt{w_k}} = \frac{\sqrt{K}}{n}, and the sum over xx with the hard γx(k)\gamma_x(k) is the sum over XkX_k of x−ckx - c_k, which is vk(X)v_k(X) by Lemma 1. The factor K/n\sqrt K / n is positive and the same for all blocks, so L2 normalization removes it. □\square

With the true soft posteriors the two vectors differ. The difference goes to zero as the components move apart, because then each posterior goes to 0 or 1 for almost every descriptor.

What is not claimed. None of these facts says that VLAD ranks images well. The retrieval quality of VLAD, and the gain of power and intra-normalization, are benchmark results.

Complexity

In the real RAM, line L3 costs O(KD)O(K D) with a linear scan over the centers, so lines L2 to L4 cost O(nKD)O(n K D). Lines L5 to L8 cost O(KD)O(K D). Extra space is the KDK D entries of the output. With an approximate nearest center search (a k-d tree or a randomized k-d forest), line L3 costs less, but then the assignment is approximate.

The output size is fixed: K=64K = 64 centers and SIFT with D=128D = 128 give 8,192 values, whatever nn is. Comparing two images costs O(KD)O(K D). For large collections the vector is reduced with principal component analysis and coded with product quantization, so that one image takes a few dozen bytes.

Properties

  • Order invariant and additive. The unnormalized blocks of X∪YX \cup Y (disjoint sets) are the sums of the blocks of XX and of YY. This is useful when descriptors arrive in batches, for example over the frames of a video.
  • Dense. Almost every entry is nonzero, unlike the sparse bag of words histogram. An inverted file does not help, and search is nearest neighbor search on dense vectors.
  • First order only. VLAD keeps the offset of the cell mean from the center, weighted by the count. It does not keep the spread of the cell (the Fisher vector keeps a second order term for that), and it keeps the count only through the length of the offset.
  • Not invariant to the codebook. A different k-means run gives different centers and a different vector space. Vectors made with different codebooks cannot be compared.
  • Exact. The code computes the definition exactly up to floating point rounding; the tests compare it with a direct evaluation of the match kernel.

Variants and improvements

  • Power normalization (Jegou et al. 2012). Line L7 with α=0.5\alpha = 0.5 reduces the weight of large components, which come from many similar descriptors (bursts such as repeated windows on a facade).
  • Intra-normalization (Arandjelovic and Zisserman 2013). Line L5 makes each cell contribute a unit vector, so one bursty cell cannot dominate. They also adapt the centers to a new data set without recomputing the whole vocabulary, and pool VLADs over several regions of the image.
  • Soft assignment. Each descriptor adds weighted residuals to several near centers. NetVLAD (Arandjelovic et al. 2016) uses a softmax of wk⊤x+bkw_k^\top x + b_k with trainable wkw_k, bkb_k and ckc_k on top of a convolutional network, and is trained for place recognition. The network is outside this page.
  • Fisher vector. Soft assignment by a Gaussian mixture, with gradients for the means and the variances, gives the Fisher vector.
  • Residual normalization. Some systems scale each residual x−ckx - c_k to unit length before line L4, so that each descriptor counts equally.

When to use it

Use VLAD when each image must be one vector of fixed size: for search in very large collections with compressed codes, for place recognition, or as input to a linear classifier. It needs only a small codebook (tens to hundreds of centers), so training is cheap. For the best accuracy with a few hundred thousand images, a bag of words with a large vocabulary and spatial verification can rank better, because VLAD keeps no geometry. Today, VLAD on learned features (NetVLAD) is common for place recognition.

Pitfalls

  • Forgetting the normalization. Without line L8, images with more descriptors get longer vectors and higher scores. Without line L7 or L5, bursts dominate. These steps are not optional details: they change the ranking.
  • Cancellation. Residuals on opposite sides of a center cancel, as in the example. A cell with many descriptors can have a short block. This is part of the method, but it means that the length of vkv_k is not a count.
  • Empty cells. An image with no descriptor in cell kk has vk=0v_k = 0. Intra-normalization must skip such blocks, or it divides by zero.
  • Codebook from other data. Centers learned on one kind of image fit another kind poorly, and the residuals become large and similar for all images. Adapt the centers or learn them on similar data.
  • Signs of the power step. Line L7 must keep the sign. Taking ∣zi∣α|z_i|^\alpha alone loses half of the information.

Implementations

The Python code computes the blocks, the optional intra-normalization, the signed power and the final L2 normalization, with a linear scan for the nearest center and the tie rule of this page. It also has a direct match-kernel function for the tests. The tests check the example of this page, the cancellation, the invariance to the order of the descriptors, the identity vk=nk(xˉk−ck)v_k = n_k(\bar x_k - c_k), the equality of the inner product with the match kernel on random sets, and the equality with the hard-assignment Fisher vector mean gradient after normalization.

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.

vlad.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/vlad/. The authors are listed in prov/D9847P.jsonl.
"""VLAD: the vector of locally aggregated descriptors.

Each local descriptor x (a list of D floats) is assigned to its nearest center
c_k of a fixed codebook C of K centers, ties going to the smaller index. For
each center the residuals x - c_k of its descriptors are summed, and the K
sums are concatenated into one vector of K D values. Optional steps: intra
normalization (each block of D values scaled to unit L2 norm), power
normalization z -> sign(z) |z|^alpha, and a final L2 normalization.
Standard library only. Cost: O(n K D) for n descriptors with a linear scan
for the nearest center, and O(K D) extra space.
"""

import math


def sq_dist(a, b):
    """Squared Euclidean distance of two vectors."""
    return sum((x - y) * (x - y) for x, y in zip(a, b))


def nearest_center(x, centers):
    """Index of the nearest center; ties go to the smaller index."""
    best, best_d = 0, sq_dist(x, centers[0])
    for k in range(1, len(centers)):
        d = sq_dist(x, centers[k])
        if d < best_d:
            best, best_d = k, d
    return best


def l2_normalize(z):
    """Scale z to unit L2 norm; the zero vector stays zero."""
    s = math.sqrt(sum(t * t for t in z))
    if s == 0.0:
        return list(z)
    return [t / s for t in z]


def power_normalize(z, alpha):
    """Signed power: sign(t) |t|^alpha for each entry. alpha = 0.5 is the signed square root."""
    return [math.copysign(abs(t) ** alpha, t) if t != 0 else 0.0 for t in z]


def vlad_blocks(descriptors, centers):
    """The K residual sums v_k (lists of D floats), before any normalization."""
    K, D = len(centers), len(centers[0])
    v = [[0.0] * D for _ in range(K)]  # @line L1
    for x in descriptors:  # @line L2
        k = nearest_center(x, centers)  # @line L3
        ck = centers[k]
        vk = v[k]
        for i in range(D):  # @line L4
            vk[i] += x[i] - ck[i]
    return v


def vlad(descriptors, centers, alpha=1.0, intra=False, l2=True):
    """The VLAD vector of a set of descriptors, as a flat list of K D floats.

    alpha = 1.0 means no power normalization; Jegou et al. use alpha = 0.5.
    intra = True scales each block to unit norm first (Arandjelovic and Zisserman).
    """
    v = vlad_blocks(descriptors, centers)
    if intra:  # @line L5
        v = [l2_normalize(block) for block in v]
    z = [t for block in v for t in block]  # @line L6
    if alpha != 1.0:  # @line L7
        z = power_normalize(z, alpha)
    if l2:  # @line L8
        z = l2_normalize(z)
    return z  # @line L9


def sum_match_kernel(xs, ys, centers):
    """Brute force: the sum over pairs (x, y) in the same cell k of <x - c_k, y - c_k>."""
    total = 0.0
    for x in xs:
        kx = nearest_center(x, centers)
        for y in ys:
            if nearest_center(y, centers) == kx:
                c = centers[kx]
                total += sum((a - ci) * (b - ci) for a, b, ci in zip(x, y, c))
    return total


def cell_means(descriptors, centers):
    """For each center: the count n_k and the mean of its descriptors (None if empty)."""
    K, D = len(centers), len(centers[0])
    sums = [[0.0] * D for _ in range(K)]
    counts = [0] * K
    for x in descriptors:
        k = nearest_center(x, centers)
        counts[k] += 1
        for i in range(D):
            sums[k][i] += x[i]
    means = [None if counts[k] == 0 else [s / counts[k] for s in sums[k]] for k in range(K)]
    return counts, means
test_vlad.py 118 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/vlad/. The authors are listed in prov/D9847P.jsonl.

import math
import random

from vlad import (cell_means, l2_normalize, nearest_center, power_normalize,
                  sum_match_kernel, vlad, vlad_blocks)

CENTERS = [[0.0, 0.0], [4.0, 0.0]]
X = [[1.0, 1.0], [-1.0, 2.0], [3.0, 1.0], [5.0, -1.0], [6.0, 0.0]]
TOL = 1e-12


def close(a, b, tol=TOL):
    return len(a) == len(b) and all(abs(x - y) <= tol for x, y in zip(a, b))


def random_set(rng, n, D):
    return [[rng.uniform(-3.0, 3.0) for _ in range(D)] for _ in range(n)]


def test_example_of_the_page():
    assert vlad_blocks(X, CENTERS) == [[0.0, 3.0], [2.0, 0.0]]
    assert close(vlad(X, CENTERS), [0.0, 3 / math.sqrt(13), 2 / math.sqrt(13), 0.0])
    assert close(vlad(X, CENTERS, alpha=0.5), [0.0, math.sqrt(3 / 5), math.sqrt(2 / 5), 0.0])
    h = 1 / math.sqrt(2)
    assert close(vlad(X, CENTERS, intra=True), [0.0, h, h, 0.0])


def test_residuals_cancel_in_a_cell():
    # (3, 1) and (5, -1) have residuals (-1, 1) and (1, -1) to (4, 0): they cancel.
    assert vlad_blocks([[3.0, 1.0], [5.0, -1.0]], CENTERS) == [[0.0, 0.0], [0.0, 0.0]]


def test_tie_goes_to_smaller_index():
    assert nearest_center([2.0, 5.0], CENTERS) == 0


def test_dimension_and_unit_norm():
    rng = random.Random(1)
    for K, D in [(1, 3), (4, 2), (8, 5)]:
        C = random_set(rng, K, D)
        z = vlad(random_set(rng, 30, D), C, alpha=0.5)
        assert len(z) == K * D
        assert abs(sum(t * t for t in z) - 1.0) < 1e-12


def test_order_of_descriptors_does_not_matter():
    rng = random.Random(2)
    C = random_set(rng, 5, 4)
    xs = random_set(rng, 40, 4)
    ys = list(xs)
    rng.shuffle(ys)
    assert close(vlad(xs, C, alpha=0.5, intra=True), vlad(ys, C, alpha=0.5, intra=True), 1e-12)


def test_block_is_count_times_mean_minus_center():
    rng = random.Random(3)
    C = random_set(rng, 6, 3)
    xs = random_set(rng, 50, 3)
    v = vlad_blocks(xs, C)
    counts, means = cell_means(xs, C)
    for k in range(6):
        if counts[k] == 0:
            assert v[k] == [0.0, 0.0, 0.0]
        else:
            expect = [counts[k] * (m - c) for m, c in zip(means[k], C[k])]
            assert close(v[k], expect, 1e-9)


def test_inner_product_is_the_sum_match_kernel():
    rng = random.Random(4)
    for _ in range(5):
        C = random_set(rng, 4, 3)
        xs, ys = random_set(rng, 15, 3), random_set(rng, 12, 3)
        a = vlad(xs, C, l2=False)
        b = vlad(ys, C, l2=False)
        dot = sum(s * t for s, t in zip(a, b))
        assert abs(dot - sum_match_kernel(xs, ys, C)) < 1e-9


def test_equals_hard_fisher_mean_gradient_up_to_scale():
    # Fisher vector mean part with hard assignment, w_k = 1/K and sigma = 1:
    # G_k = (1 / (T sqrt(w_k))) sum over the cell of (x - mu_k).
    rng = random.Random(5)
    K, D, T = 5, 3, 40
    C = random_set(rng, K, D)
    xs = random_set(rng, T, D)
    g = [[0.0] * D for _ in range(K)]
    for x in xs:
        k = nearest_center(x, C)
        for i in range(D):
            g[k][i] += (x[i] - C[k][i]) / (T * math.sqrt(1.0 / K))
    flat_g = [t for block in g for t in block]
    v = vlad(xs, C, l2=False)
    assert close(flat_g, [math.sqrt(K) / T * t for t in v], 1e-12)
    assert close(l2_normalize(flat_g), vlad(xs, C), 1e-12)


def test_intra_normalization_blocks():
    rng = random.Random(6)
    C = random_set(rng, 6, 4)
    xs = random_set(rng, 8, 4)
    z = vlad(xs, C, intra=True, l2=False)
    for k in range(6):
        s = sum(t * t for t in z[4 * k:4 * k + 4])
        assert abs(s - 1.0) < 1e-12 or s == 0.0


def test_power_normalization_keeps_sign():
    z = [-4.0, 0.0, 9.0, -0.25]
    assert power_normalize(z, 0.5) == [-2.0, 0.0, 3.0, -0.5]
    assert power_normalize(z, 1.0) == z


def test_empty_set_gives_zero_vector():
    assert vlad([], CENTERS) == [0.0, 0.0, 0.0, 0.0]

History

Jegou, Douze, Schmid and Perez introduced VLAD at CVPR 2010 as a compact alternative to the bag of words, to be combined with dimension reduction and product quantization for search in collections of millions of images. The 2012 journal version with Perronnin and Sanchez adds power normalization, compares VLAD with the Fisher vector of Perronnin and Dance (2007), and shows that VLAD is a simplified Fisher vector. Arandjelovic and Zisserman (2013) proposed intra-normalization and vocabulary adaptation. Arandjelovic et al. (2016) made VLAD a trainable layer, NetVLAD, for place recognition.

References

  1. Herve Jegou, Matthijs Douze, Cordelia Schmid and Patrick Perez, Aggregating local descriptors into a compact image representation, CVPR 2010, 3304-3311, The definition of VLAD as the sum of the residuals to the nearest center, followed by L2 normalization, and its use with compact codes
  2. Herve Jegou, Florent Perronnin, Matthijs Douze, Jorge Sanchez, Patrick Perez and Cordelia Schmid, Aggregating local image descriptors into compact codes, IEEE Transactions on Pattern Analysis and Machine Intelligence 34(9), 2012, 1704-1716, The VLAD descriptor, its power-law normalization, and VLAD as a simplified Fisher vector
  3. Relja Arandjelovic and Andrew Zisserman, All about VLAD, CVPR 2013, 1578-1585, Intra-normalization of each residual block against bursty features
  4. Jorge Sanchez, Florent Perronnin, Thomas Mensink and Jakob Verbeek, Image classification with the Fisher vector: theory and practice, International Journal of Computer Vision 105(3), 2013, 222-245, Section 2.5, Relationship with other methods (VLAD as a Fisher vector with hard assignment and only the gradient with respect to the means)
  5. Relja Arandjelovic, Petr Gronat, Akihiko Torii, Tomas Pajdla and Josef Sivic, NetVLAD: CNN architecture for weakly supervised place recognition, CVPR 2016, 5297-5307, The NetVLAD layer: soft assignment with trainable centers, intra-normalization and L2 normalization (arXiv 1511.07247)

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.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