Back to paper library
arXiv 2017CVPR 2017Person re-identificationPaper notes

k-reciprocal

Mistaken Identity

Original paper

Re-ranking Person Re-identification with k-reciprocal Encoding

Paper authors

Zhun Zhong · Liang Zheng · Donglin Cao · Shaozi Li

Publication
CVPR 2017Conference
First submitted to arXiv
arXiv:1701.08398
Cite this paper · BibTeX

The citation identifies the linked source version. It cites the original paper and its authors.

@misc{personreidkreciprocal2017,
  title = {{Re-ranking Person Re-identification with k-reciprocal Encoding}},
  author = {Zhun Zhong and Liang Zheng and Donglin Cao and Shaozi Li},
  year = {2017},
  eprint = {1701.08398},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1701.08398}
}
On this page

Person re-identification (re-ID) is usually treated as a retrieval problem. Given an image of a person taken by one camera, called the query (probe), the system ranks a large set of images taken by other cameras, the gallery, so that the same person comes out on top.

Most approaches first turn each image into a feature vector and then rank by some distance. The top few results are often mixed with "other people who look very similar". Same white top, same denim shorts, and at surveillance-camera resolution their feature distance can be smaller than that of the same person seen from another angle.

Image retrieval had re-ranking methods long before. Chum et al.'s average query expansion (AQE) averages the features of the top results into a new query and searches again; Jegou et al.'s CDM corrects similarities using the average distance from each point to its surrounding neighbors; Qin et al. proposed k-reciprocal nearest neighbors in 2011, treating as highly relevant only images that are "in each other's top k". On the person re-identification side, re-ranking methods were far fewer, and some needed human interaction or extra annotation.

Zhun Zhong, Donglin Cao and Shaozi Li of Xiamen University, together with Liang Zheng of the University of Technology Sydney, wanted a fully automatic re-ranking method that needs no annotation at all and can be attached directly to the ranking output of any re-ID system.

Defining the problem

Original Figure 1. The top row is a query image (blue box) and its top 10, of which P1 to P4 are the same person (green boxes) and N1 to N6 are other people. The bottom row lists the top 10 of each of these 10 images: the original query (blue box) appears in the lists of all four positives, and in none of the lists of the six negatives.
Original Figure 1, Zhong et al., from PDF page 1, arXiv license, scholarly quotation.

This figure is the starting point of the whole paper. Only 4 of the query's top 10 are correct, and the ones ranked 2nd and 4th are both other people. Turn it around and look at each of these 10 images' own top 10. The 4 correct ones all include the original query, and not one of the 6 wrong ones does.

A look-alike can show up among the query's top results, but from the look-alike's side, the query usually isn't among its top results. Only when each side picks the other are the two likely to be the same person.

The problem takes a simple form. Between the query pp and a gallery image gig_i, the original distance is first computed as a Mahalanobis distance:

d(p,gi)=(xp−xgi)⊤M (xp−xgi)d(p, g_i) = (x_p - x_{g_i})^\top M \, (x_p - x_{g_i})

xx is the appearance feature and MM a positive semidefinite matrix; with the identity matrix, this is the squared Euclidean distance. Ranking by this distance gives the initial list, and the goal is to re-rank it so that more positives move to the top.

Solving the problem

k-reciprocal neighbors

N(p,k)N(p, k) is the top kk of pp. k-reciprocal neighbors keep only the images that are each in the other's top kk:

R(p,k)={ gi∣ gi∈N(p,k)∧ p∈N(gi,k) }\begin{aligned} R(p, k) = \{\, g_i \mid\ & g_i \in N(p, k) \\ & \wedge\ p \in N(g_i, k) \,\} \end{aligned}

This condition is stricter than a plain top kk, and far fewer false matches get through. The price is that true matches can be blocked as well. When the same person switches cameras, turns their back or is half occluded, their distance to the query grows, and they can't even get into N(p,k)N(p, k), let alone R(p,k)R(p, k).

Expansion

Original Figure 3. The top row is R(Q, 20) of the query Q, six images A to F; C among them is a back view of someone carrying a yellow-green backpack. In the middle is C's R(C, 10), which contains B, G and Q, where G is another back view of the same person. After the union of the two sets, R*(Q, 20) in the bottom row has gained G.
Original Figure 3, Zhong et al., from PDF page 3, arXiv license, scholarly quotation.

The authors' remedy is to borrow the neighbors' neighbors. For each candidate qq in R(p,k)R(p, k), take its smaller neighbor set R(q,12k)R(q, \tfrac{1}{2}k); if at least two-thirds of that set already falls inside R(p,k)R(p, k), merge the whole set in:

R∗(p,k)←R(p,k)∪R(q,12k)R^*(p, k) \leftarrow R(p, k) \cup R(q, \tfrac{1}{2}k)

G in the figure above is a back view, too different from the front-facing query Q to be in R(Q,20)R(Q, 20). But C is also a back view, G is among C's neighbors, and most of C's neighbors are already Q's neighbors, so G gets brought in. The two-thirds threshold is there to keep a whole crowd of other people from being dragged in along with it.

The expanded set isn't used directly as the top results. The authors treat it as context and recompute the distance between the query and each gallery image.

Jaccard distance

If two images show the same person, their neighbor sets should overlap a lot. The Jaccard distance between the sets measures this directly:

dJ(p,gi)=1−∣R∗(p,k)∩R∗(gi,k)∣∣R∗(p,k)∪R∗(gi,k)∣d_J(p, g_i) = 1 - \frac{|R^*(p, k) \cap R^*(g_i, k)|}{|R^*(p, k) \cup R^*(g_i, k)|}

Written this way, it has three problems. Computing set intersections and unions for every pair of images is slow; every neighbor weighs the same, so one very close to the query counts no more than one that barely squeezed in; and with context alone, variations in lighting and pose leave the distance with little discriminative power.

The first two problems are solved with the same trick. Write the neighbor set as an NN-dimensional vector VpV_p whose ii-th dimension is the weight of gig_i: 0 if it isn't in the set, and if it is, a Gaussian-kernel weight based on the original distance:

Vp,gi={e−d(p,gi),gi∈R∗(p,k)0,otherwiseV_{p, g_i} = \begin{cases} e^{-d(p, g_i)}, & g_i \in R^*(p, k) \\ 0, & \text{otherwise} \end{cases}

The size of the intersection becomes the sum of element-wise minimums, and the union the sum of element-wise maximums, so set operations turn into vector operations:

dJ(p,gi)=1−∑jmin⁡(Vp,gj,Vgi,gj)∑jmax⁡(Vp,gj,Vgi,gj)d_J(p, g_i) = 1 - \frac{\sum_j \min(V_{p, g_j}, V_{g_i, g_j})}{\sum_j \max(V_{p, g_j}, V_{g_i, g_j})}

This approach of "encoding the neighbor set as a vector and comparing with a generalized Jaccard distance" comes from Bai and Bai's sparse contextual activation (SCA), and the authors' README also asks users to cite it.

Local query expansion

Images of the same person should have features close to one another. The authors average the vectors of the query's top k2k_2 and use the result in place of the query's own vector:

Vp=1∣N(p,k2)∣∑gi∈N(p,k2)VgiV_p = \frac{1}{|N(p, k_2)|} \sum_{g_i \in N(p, k_2)} V_{g_i}

Both the query and the gallery go through this step. The top k2k_2 inevitably contains some mistakes, so k2k_2 has to be much smaller than the k1k_1 used to build R∗R^*.

Final distance

Original Figure 2. The re-ranking pipeline, in four stages: sampling, feature extraction, distance calculation and aggregation. Every image in the query and the gallery has an appearance feature x and a k-reciprocal feature V; the former goes through a Mahalanobis metric to give the original distance d, the latter through a Jaccard metric to give the Jaccard distance d_J, and the two are aggregated into the final distance d*.
Original Figure 2, Zhong et al., from PDF page 2, arXiv license, scholarly quotation.

The third problem is solved by adding the original distance back:

d∗(p,gi)=(1−λ) dJ(p,gi)+λ d(p,gi)d^*(p, g_i) = (1 - \lambda)\, d_J(p, g_i) + \lambda\, d(p, g_i)

With λ=0\lambda = 0 only the Jaccard distance counts; with λ=1\lambda = 1 it's the original ranking. Finally everything is re-ranked by d∗d^* in ascending order.

The whole method has no parameters to train. The computation lies in the pairwise distances within the gallery, O(N2)O(N^2) for NN gallery images, plus O(N2log⁡N)O(N^2 \log N) for the sorting. The authors' argument is that this part can be computed offline in advance; when a new query comes in, it needs only one round of distances to the gallery, O(N)O(N), and one more sort.

Discussion

Except in the CUHK03 single-shot setting, all experiments use k1=20k_1 = 20, k2=6k_2 = 6, λ=0.3\lambda = 0.3.

Market-1501

Methodrank-1mAP
BOW35.8414.75
BOW + re-ranking39.8519.90
LOMO + XQDA43.5622.44
LOMO + XQDA + re-ranking48.3432.21
IDE (ResNet-50)72.5446.00
+ AQE73.2050.14
+ CDM73.6649.53
+ re-ranking74.8559.87
IDE (ResNet-50) + KISSME + re-ranking77.1163.63

Market-1501 has 750 people, 3,368 query images and 19,732 test images. With hand-crafted features and CNN features alike, re-ranking helps, and mAP gains far more than rank-1. Taking ResNet-50 IDE features as an example, rank-1 rises by 2.3 points and mAP by nearly 14.

rank-1 only checks whether the first result is right, while mAP looks at where every positive is ranked. What re-ranking mainly does is pull up positives that switched angle or turned their back and were originally ranked far down; when the first result is already right, it can't add much.

Among re-ranking methods, AQE and CDM add only 3.5 to 4.1 points of mAP. The best combination, 77.11/63.63, is well ahead of the best entry in the table at the time, Gated, at 65.88/39.55.

CUHK03

CUHK03's original protocol is single-shot. Each person has only two cameras, and only one image in the gallery is correct, so re-ranking has almost no effect.

Method (labeled)rank-1mAP
LOMO + XQDA49.756.4
LOMO + XQDA + re-ranking50.056.8
IDE (CaffeNet) + XQDA61.767.6
IDE (CaffeNet) + XQDA + re-ranking61.667.6

The authors admit as much. With only one positive, there isn't enough context, and the whole method rests on the premise that "the gallery holds several images of the same person".

So the authors defined a separate protocol modeled on Market-1501. 767 people are used for training and 700 for testing, with one image per person per camera picked at random as a query and the rest put into the gallery. Under this protocol, the labeled results of IDE (ResNet-50) + XQDA improve from 32.0/29.6 to 38.1/40.3. This split was later put in the repo under the name CUHK03-NP, and the README asks anyone who uses it to cite this paper.

MARS and PRW

MARS is a video dataset of 1,261 people and about twenty thousand sequences cut automatically by a detector and a tracker. Each sequence's feature is extracted frame by frame and then max-pooled. IDE (ResNet-50) + XQDA improves from 70.51/55.12 to 73.94/68.45, once again more than ten points of mAP. The appearance network in [17.03] DeepSORT: Know the Face, Not the Box uses this very dataset.

PRW requires detecting pedestrians in the raw frames first, then finding the person among the detected boxes. CaffeNet IDE features go from 51.03/25.09 to 52.54/31.51, the same pattern of improvement: a little rank-1, six points of mAP.

Parameters

The parameter analysis was done on a validation set of 200 people split off from the Market-1501 training set.

Too small a k1k_1 and the neighbor set carries little context; too large and more false matches creep in. mAP first rises with k1k_1 and then slowly declines, and rank-1 is best around 20. k2=1k_2 = 1 amounts to no local query expansion; within a reasonable range, the larger k2k_2 the better, but too large and it starts pulling in wrong ones.

λ=0\lambda = 0, using only the Jaccard distance, already beats the original ranking; with a little of the original distance added in, λ\lambda around 0.3 works best.

Code

The official repo has 618 stars and holds the Caffe IDE baseline, the MATLAB re-ranking and the CUHK03-NP split, with no license file. The Python versions were contributed later by other people.

The paper says the gallery part can be computed offline, so a new query costs only O(N)O(N). The official evaluation code doesn't run that way. The Market-1501 evaluation script calls re_ranking([probFea galFea], ...), building the neighbor graph and computing Jaccard distances for the 3,368 queries and the 19,732 gallery images all together. Each person has more than four queries on average, from different cameras, and these too can appear in one another's neighbor sets and vouch for each other. A single 23,100 × 23,100 matrix takes more than 2 GB even in single precision, and the code holds several of them at once.

The code also differs from the paper in a few small ways. Distances are first divided by each row's maximum, the Gaussian-kernel weights are further divided by their sum, and the expansion threshold is strictly greater than two-thirds.

The GitHub issues keep circling the same point. In 2018 someone tried it on VIPeR, where the gallery has only one image per person, and re-ranking made things worse; the authors replied that "our approach assumes that there are multi positive samples in the gallery", which matches the CUHK03 single-shot results. In March 2019 someone asked why rank-1 "really improved" while rank-2 to rank-10 "dropped significantly". In the same thread, the authors answered two questions from another commenter: rank-2 to rank-10 are in the CMC, and for code that draws the ranking results, there's a tutorial repo to look at. The original question is still open today (where to find rank-2 got a tutorial; why it dropped got nothing). In November of the same year, another issue reported that both mAP and rank-1 dropped, and it never got a reply.

Conclusion

The criterion of k-reciprocal re-ranking is that two images must each be among the other's top results. Add neighbor expansion, a vectorized Jaccard distance and local query expansion on top of this criterion, and you get a post-processing step that needs no training and plugs into any feature.

Its premise is just as clear. The gallery has to hold several images of the same person, and the official numbers were computed with all the queries processed together in one batch. On datasets like Market-1501 and MARS, where the same person has several images, mAP gains more than ten points; switch to VIPeR with one image per person, or to the CUHK03 single-shot protocol, and it does almost nothing.

Re-ranking later became a common post-processing step in re-ID, and comparisons between methods have to say up front whether it was used. In 2022, [22.11] CLIP-ReID: Give It a Name made a point of noting right before its main tables that "all data listed here are without re-ranking".