TExcelTAD
Home › Computer Vision: Images to Detection, Segmentation & Tracking › Project 6: Person Re-Identification

Project 6: Person Re-Identification

In this project you build and evaluate a cross-camera person search: given a crop of a person from camera A, rank the crops of camera B so that the same person comes first. You compare three classical baselines, a generic deep network and a metric learned on training identities, measure them with CMC and mAP on people the methods have never seen, test how the results hold up as the gallery fills with strangers, and finish with a privacy assessment, which for this task is part of the deliverable, not an appendix.

The methods and the metrics come from person re-identification; read it first. This project uses a harder version of its synthetic pedestrians.

Note: All "people" here are drawn in code. A real re-ID system processes personal data of everyone who walks past a camera, and can reconstruct where a person went and when. It needs a lawful purpose, a data protection impact assessment, retention limits and access controls before the first camera is connected (privacy, consent and licensing). The write-up template at the end has a section for each.

Goal and success criteria

Item Target
Task rank camera-B crops for each camera-A query crop
Data 50 synthetic identities; identities 0 to 24 for training and tuning, 25 to 49 for testing only
Metrics rank-1, rank-5 (CMC) and mAP on the 25 test identities (25 queries, 50 gallery crops)
Robustness rank-1 and mAP as distractors (strangers seen only by camera B) are added to the gallery
Success the best method beats the raw-pixel baseline by at least 0.2 mAP on the test identities, and its loss with 1,000 distractors is reported

Splitting by identity is the rule that matters most: a method that learned what person 30 looks like must not be tested on person 30 (split strategies).

Step 1: harder data and three baselines

The project's generator is a variant of the course's make_person, with four changes that make it closer to real footage: every image has its own light level (gain 0.7 to 1.3), the horizontal shift is up to 4 pixels, 30 % of the crops have an occluder (a bag, a bin, another person) in front of the legs, and camera B differs from camera A not only by a colour gain but also by a tone curve (gamma 0.8) and a colour offset, which grey-world normalisation can undo only partly.

python · try it yourself
import numpy as np
import cv2
cv2.setLogLevel(0)

CAMS = {"A": dict(gain=np.array([1.0, 1.0, 1.0]), gamma=1.0, offset=np.array([0.0, 0.0, 0.0])),
        "B": dict(gain=np.array([1.15, 1.0, 0.8]), gamma=0.8, offset=np.array([0.0, 5.0, 15.0]))}

def make_person_hard(rng, shirt, trousers, cam, h=64, w=32):
    """Project variant of make_person: per-image light, larger shift, occluders in 30 % of the crops,
    and a camera with a tone curve and an offset as well as a colour gain."""
    img = rng.normal(90, 15, (h, w, 3))
    dx = int(rng.integers(-4, 5))
    img[4:16, 11 + dx:21 + dx] = [200, 160, 130]
    img[16:38, 7 + dx:25 + dx] = shirt
    img[38:62, 9 + dx:23 + dx] = trousers
    if rng.random() < 0.3:                                            # something in front of the legs
        ow, ox = int(rng.integers(10, 17)), int(rng.integers(0, 17))
        img[int(rng.integers(30, 44)):, ox:ox + ow] = rng.integers(30, 220, 3)
    c = CAMS[cam]
    img = (img * rng.uniform(0.7, 1.3) * c["gain"]).clip(0, 255)
    img = 255 * (img / 255) ** c["gamma"] + c["offset"] + rng.normal(0, 8, (h, w, 3))
    return img.clip(0, 255).astype(np.uint8)

def make_set(rng, n_ids=50, n_gallery=2):
    shirts, trousers = rng.integers(20, 236, (n_ids, 3)), rng.integers(20, 236, (n_ids, 3))
    query = np.array([make_person_hard(rng, shirts[i], trousers[i], "A") for i in range(n_ids)])
    gallery = np.array([make_person_hard(rng, shirts[i], trousers[i], "B") for i in range(n_ids) for _ in range(n_gallery)])
    return query, np.arange(n_ids), gallery, np.repeat(np.arange(n_ids), n_gallery)

def evaluate(D, q_ids, g_ids):
    order = np.argsort(D, axis=1, kind="stable")
    matches = g_ids[order] == q_ids[:, None]
    first = matches.argmax(axis=1)
    aps = [np.mean(np.arange(1, m.sum() + 1) / (np.flatnonzero(m) + 1)) for m in matches]
    return float(np.mean(first < 1)), float(np.mean(first < 5)), float(np.mean(aps))

def grey_world(img):
    f = img.astype(float)
    means = f.reshape(-1, 3).mean(axis=0)
    return (f * means.mean() / means).clip(0, 255).astype(np.uint8)

def hsv_hist(img, bins=(12, 4)):
    hsv = cv2.cvtColor(img, cv2.COLOR_RGB2HSV)
    feats = []
    for a, b in [(0, 16), (16, 38), (38, 64)]:
        h = cv2.calcHist([np.ascontiguousarray(hsv[a:b])], [0, 1], None, list(bins), [0, 180, 0, 256]).ravel()
        feats.append(np.sqrt(h / h.sum()))
    return np.concatenate(feats)

def dist(fq, fg):
    return np.linalg.norm(fq[:, None] - fg[None], axis=2)

rng = np.random.default_rng(0)
query, q_ids, gallery, g_ids = make_set(rng)
tq, tg = q_ids >= 25, g_ids >= 25                                    # test identities only
print(f"test split: {tq.sum()} queries, {tg.sum()} gallery crops; train split: {(~tq).sum()} and {(~tg).sum()}")
print("method                       rank-1 rank-5  mAP")
feats = {
    "raw pixels": lambda x: x.reshape(len(x), -1).astype(float),
    "HSV stripes": lambda x: np.array([hsv_hist(im) for im in x]),
    "HSV stripes + grey-world": lambda x: np.array([hsv_hist(grey_world(im)) for im in x]),
}
for name, f in feats.items():
    r1, r5, mAP = evaluate(dist(f(query[tq]), f(gallery[tg])), q_ids[tq], g_ids[tg])
    print(f"{name:28s} {r1:.3f}  {r5:.3f}  {mAP:.3f}")
test split: 25 queries, 50 gallery crops; train split: 25 and 50
method                       rank-1 rank-5  mAP
raw pixels                   0.560  0.760  0.476
HSV stripes                  0.760  0.960  0.805
HSV stripes + grey-world     0.800  0.880  0.766

All scores are on the 25 test identities (25 queries, 50 gallery crops, chance rank-1 0.04). Raw pixels are now weak (rank-1 0.560, mAP 0.476): larger shifts, occluders and per-image light break pixel-by-pixel comparison, unlike in the lesson's easier data. The striped HSV histogram is much better (rank-1 0.760, rank-5 0.960, mAP 0.805). Grey-world, which was decisive in the lesson, no longer helps: rank-1 moves from 0.760 to 0.800 but mAP falls from 0.805 to 0.766 and rank-5 from 0.960 to 0.880. Camera B now applies a tone curve and an offset, and every image has its own light level, so "divide by the channel mean" is the wrong correction. With 25 queries one query is 0.04 of rank-1, so the rank-1 change is one query; the mAP drop is the more reliable signal.

Step 2: generic deep features (recorded)

ResNet-18 trained on ImageNet (not on people, and not on re-ID data) gives 512-d pooled features; the crops are resized to the usual re-ID input of 256 x 128. The same test split is used.

python · try it yourself
import numpy as np
import cv2
import torch
from torchvision.models import resnet18, ResNet18_Weights

CAMS = {"A": dict(gain=np.array([1.0, 1.0, 1.0]), gamma=1.0, offset=np.array([0.0, 0.0, 0.0])),
        "B": dict(gain=np.array([1.15, 1.0, 0.8]), gamma=0.8, offset=np.array([0.0, 5.0, 15.0]))}

def make_person_hard(rng, shirt, trousers, cam, h=64, w=32):
    img = rng.normal(90, 15, (h, w, 3))
    dx = int(rng.integers(-4, 5))
    img[4:16, 11 + dx:21 + dx] = [200, 160, 130]
    img[16:38, 7 + dx:25 + dx] = shirt
    img[38:62, 9 + dx:23 + dx] = trousers
    if rng.random() < 0.3:
        ow, ox = int(rng.integers(10, 17)), int(rng.integers(0, 17))
        img[int(rng.integers(30, 44)):, ox:ox + ow] = rng.integers(30, 220, 3)
    c = CAMS[cam]
    img = (img * rng.uniform(0.7, 1.3) * c["gain"]).clip(0, 255)
    img = 255 * (img / 255) ** c["gamma"] + c["offset"] + rng.normal(0, 8, (h, w, 3))
    return img.clip(0, 255).astype(np.uint8)

def make_set(rng, n_ids=50, n_gallery=2):
    shirts, trousers = rng.integers(20, 236, (n_ids, 3)), rng.integers(20, 236, (n_ids, 3))
    query = np.array([make_person_hard(rng, shirts[i], trousers[i], "A") for i in range(n_ids)])
    gallery = np.array([make_person_hard(rng, shirts[i], trousers[i], "B") for i in range(n_ids) for _ in range(n_gallery)])
    return query, np.arange(n_ids), gallery, np.repeat(np.arange(n_ids), n_gallery)

def evaluate(D, q_ids, g_ids):
    order = np.argsort(D, axis=1, kind="stable")
    matches = g_ids[order] == q_ids[:, None]
    first = matches.argmax(axis=1)
    aps = [np.mean(np.arange(1, m.sum() + 1) / (np.flatnonzero(m) + 1)) for m in matches]
    return float(np.mean(first < 1)), float(np.mean(first < 5)), float(np.mean(aps))

def grey_world(img):
    f = img.astype(float)
    means = f.reshape(-1, 3).mean(axis=0)
    return (f * means.mean() / means).clip(0, 255).astype(np.uint8)

torch.manual_seed(0)
net = resnet18(weights=ResNet18_Weights.IMAGENET1K_V1).eval()
net.fc = torch.nn.Identity()
mean, std = np.array([0.485, 0.456, 0.406]), np.array([0.229, 0.224, 0.225])

def embed(crops):
    x = np.stack([cv2.resize(c, (128, 256), interpolation=cv2.INTER_LINEAR) / 255.0 for c in crops])
    x = torch.tensor(((x - mean) / std).transpose(0, 3, 1, 2), dtype=torch.float32)
    with torch.no_grad():
        e = net(x).numpy()
    return e / np.linalg.norm(e, axis=1, keepdims=True)

rng = np.random.default_rng(0)
query, q_ids, gallery, g_ids = make_set(rng)
tq, tg = q_ids >= 25, g_ids >= 25
print("method                       rank-1 rank-5  mAP")
for name, prep in [("ResNet-18 (ImageNet)", lambda im: im), ("ResNet-18 + grey-world", grey_world)]:
    fq = embed([prep(im) for im in query[tq]]); fg = embed([prep(im) for im in gallery[tg]])
    r1, r5, mAP = evaluate(1 - fq @ fg.T, q_ids[tq], g_ids[tg])
    print(f"{name:28s} {r1:.3f}  {r5:.3f}  {mAP:.3f}")
method                       rank-1 rank-5  mAP
ResNet-18 (ImageNet)         0.360  0.680  0.348
ResNet-18 + grey-world       0.440  0.720  0.429

Generic ImageNet features are the weakest method so far (rank-1 0.360, mAP 0.348, below raw pixels), and grey-world helps them only a little (0.440, 0.429). An ImageNet network describes objects and textures, and these crops differ mainly in a few flat colours under a camera shift it was never trained to ignore. This does not mean deep learning fails at re-ID: networks trained on re-ID data are the state of the art. It means a generic backbone is not a re-ID model, which is worth one recorded experiment to prove before anyone suggests it.

Step 3: learning the camera difference on training identities

The baselines show that the camera's tone curve is the main obstacle: grey-world undoes a colour gain, not a gamma curve with an offset. But the training identities were seen by both cameras, so the mapping from camera-B colours to camera-A colours can be learned from them. The classical re-ID tool for this is the brightness transfer function (BTF; Javed and colleagues, 2005): for each channel, match the distribution of camera-B intensities to the distribution of camera-A intensities of the same people, which gives a monotone lookup table fcf_c with

fc(v)=FA,c−1(FB,c(v))f_c(v) = F_{A,c}^{-1}\big(F_{B,c}(v)\big)

where FA,cF_{A,c} and FB,cF_{B,c} are the cumulative intensity distributions of channel cc in the two cameras (histogram matching, histograms and thresholding). It is fitted on identities 0 to 24 only and applied to the gallery crops of the test identities. The example also tries a second learned step, linear discriminant analysis (LDA) on the features, which looks for the directions that separate identities, and shows what fitting it on the test identities would do.

python · try it yourself
import numpy as np
import cv2
from sklearn.discriminant_analysis import LinearDiscriminantAnalysis
cv2.setLogLevel(0)

CAMS = {"A": dict(gain=np.array([1.0, 1.0, 1.0]), gamma=1.0, offset=np.array([0.0, 0.0, 0.0])),
        "B": dict(gain=np.array([1.15, 1.0, 0.8]), gamma=0.8, offset=np.array([0.0, 5.0, 15.0]))}

def make_person_hard(rng, shirt, trousers, cam, h=64, w=32):
    img = rng.normal(90, 15, (h, w, 3))
    dx = int(rng.integers(-4, 5))
    img[4:16, 11 + dx:21 + dx] = [200, 160, 130]
    img[16:38, 7 + dx:25 + dx] = shirt
    img[38:62, 9 + dx:23 + dx] = trousers
    if rng.random() < 0.3:
        ow, ox = int(rng.integers(10, 17)), int(rng.integers(0, 17))
        img[int(rng.integers(30, 44)):, ox:ox + ow] = rng.integers(30, 220, 3)
    c = CAMS[cam]
    img = (img * rng.uniform(0.7, 1.3) * c["gain"]).clip(0, 255)
    img = 255 * (img / 255) ** c["gamma"] + c["offset"] + rng.normal(0, 8, (h, w, 3))
    return img.clip(0, 255).astype(np.uint8)

def make_set(rng, n_ids=50, n_gallery=2):
    shirts, trousers = rng.integers(20, 236, (n_ids, 3)), rng.integers(20, 236, (n_ids, 3))
    query = np.array([make_person_hard(rng, shirts[i], trousers[i], "A") for i in range(n_ids)])
    gallery = np.array([make_person_hard(rng, shirts[i], trousers[i], "B") for i in range(n_ids) for _ in range(n_gallery)])
    return query, np.arange(n_ids), gallery, np.repeat(np.arange(n_ids), n_gallery)

def evaluate(D, q_ids, g_ids):
    order = np.argsort(D, axis=1, kind="stable")
    matches = g_ids[order] == q_ids[:, None]
    first = matches.argmax(axis=1)
    aps = [np.mean(np.arange(1, m.sum() + 1) / (np.flatnonzero(m) + 1)) for m in matches]
    return float(np.mean(first < 1)), float(np.mean(first < 5)), float(np.mean(aps))

def hsv_hist(img, bins=(12, 4)):
    hsv = cv2.cvtColor(img, cv2.COLOR_RGB2HSV)
    feats = []
    for a, b in [(0, 16), (16, 38), (38, 64)]:
        h = cv2.calcHist([np.ascontiguousarray(hsv[a:b])], [0, 1], None, list(bins), [0, 180, 0, 256]).ravel()
        feats.append(np.sqrt(h / h.sum()))
    return np.concatenate(feats)

def learn_btf(A, B):
    """Brightness transfer function camera B -> camera A, one lookup table per channel, learned by matching
    the pooled intensity distributions of training crops of the same people seen by both cameras."""
    lut = np.zeros((3, 256), np.uint8)
    for c in range(3):
        a, b = A[..., c].ravel(), np.sort(B[..., c].ravel())
        cdf_b = np.searchsorted(b, np.arange(256), side="right") / len(b)
        lut[c] = np.quantile(a, cdf_b).round().clip(0, 255)
    return lut

def apply_btf(img, lut):
    return np.stack([lut[c][img[..., c]] for c in range(3)], axis=-1)

def dist(fq, fg):
    return np.linalg.norm(fq[:, None] - fg[None], axis=2)

rng = np.random.default_rng(0)
query, q_ids, gallery, g_ids = make_set(rng)
tq, tg = q_ids >= 25, g_ids >= 25
lut = learn_btf(query[~tq], gallery[~tg])                       # training identities only
print("learned B -> A lookup at 0, 64, 128, 192, 255 (R, G, B):", lut[:, [0, 64, 128, 192, 255]].tolist())

Fq = np.array([hsv_hist(im) for im in query]); Fg = np.array([hsv_hist(im) for im in gallery])
Fg_btf = np.array([hsv_hist(apply_btf(im, lut)) for im in gallery])
print("method                         rank-1 rank-5  mAP")
for name, G in [("HSV stripes", Fg), ("BTF + HSV stripes", Fg_btf)]:
    r1, r5, mAP = evaluate(dist(Fq[tq], G[tg]), q_ids[tq], g_ids[tg])
    print(f"{name:30s} {r1:.3f}  {r5:.3f}  {mAP:.3f}")

# A second learned step: LDA on the BTF features, fitted on the training identities
X_train = np.vstack([Fq[~tq], Fg_btf[~tg]]); y_train = np.concatenate([q_ids[~tq], g_ids[~tg]])
lda = LinearDiscriminantAnalysis(solver="eigen", shrinkage="auto", n_components=16).fit(X_train, y_train)
r1, r5, mAP = evaluate(dist(lda.transform(Fq[tq]), lda.transform(Fg_btf[tg])), q_ids[tq], g_ids[tg])
print(f"{'BTF + HSV + LDA (train ids)':30s} {r1:.3f}  {r5:.3f}  {mAP:.3f}")

# The leak to avoid: fitting LDA on the test identities themselves
leak = LinearDiscriminantAnalysis(solver="eigen", shrinkage="auto", n_components=16).fit(
    np.vstack([Fq[tq], Fg_btf[tg]]), np.concatenate([q_ids[tq], g_ids[tg]]))
r1, r5, mAP = evaluate(dist(leak.transform(Fq[tq]), leak.transform(Fg_btf[tg])), q_ids[tq], g_ids[tg])
print(f"{'LDA fitted on TEST ids (leak)':30s} {r1:.3f}  {r5:.3f}  {mAP:.3f}")
learned B -> A lookup at 0, 64, 128, 192, 255 (R, G, B): [[0, 42, 99, 164, 255], [0, 43, 106, 177, 255], [0, 46, 121, 211, 255]]
method                         rank-1 rank-5  mAP
HSV stripes                    0.760  0.960  0.805
BTF + HSV stripes              0.960  1.000  0.970
BTF + HSV + LDA (train ids)    0.680  0.680  0.672
LDA fitted on TEST ids (leak)  1.000  1.000  0.988

The learned lookup tables show the camera model: camera-B values 64 and 128 map back to 42 and 99 in red (B's red gain and tone curve reversed) and to 46 and 121 in blue. With the BTF, the striped histogram finds the right person first for 24 of 25 test queries (rank-1 0.960, rank-5 1.000, mAP 0.970), an mAP gain of 0.494 over raw pixels: the success criterion is met. LDA on top makes things worse (mAP 0.672): with 25 training identities and 144 features it learns the directions that separate those 25 people's clothes, which says nothing about the colours of new people. The leak row (mAP 0.988) is what you would report if you fitted LDA on the test identities: a near-perfect, meaningless number. Of the two learned steps, the one that models what really differs between the cameras (the colour mapping) generalises; the one that models the training people does not.

Step 4: the distractor effect

A benchmark gallery of 50 crops is tiny. A real gallery holds every person who walked past camera B in the search window, almost all of whom are not the person you are looking for. The next example keeps the 25 test queries and their 50 true gallery crops and adds 0 to 1,000 distractors: crops of new identities seen only by camera B. Each distractor is one more chance for a lookalike to push the true match down the ranking.

python · try it yourself
import numpy as np
import cv2
cv2.setLogLevel(0)

CAMS = {"A": dict(gain=np.array([1.0, 1.0, 1.0]), gamma=1.0, offset=np.array([0.0, 0.0, 0.0])),
        "B": dict(gain=np.array([1.15, 1.0, 0.8]), gamma=0.8, offset=np.array([0.0, 5.0, 15.0]))}

def make_person_hard(rng, shirt, trousers, cam, h=64, w=32):
    img = rng.normal(90, 15, (h, w, 3))
    dx = int(rng.integers(-4, 5))
    img[4:16, 11 + dx:21 + dx] = [200, 160, 130]
    img[16:38, 7 + dx:25 + dx] = shirt
    img[38:62, 9 + dx:23 + dx] = trousers
    if rng.random() < 0.3:
        ow, ox = int(rng.integers(10, 17)), int(rng.integers(0, 17))
        img[int(rng.integers(30, 44)):, ox:ox + ow] = rng.integers(30, 220, 3)
    c = CAMS[cam]
    img = (img * rng.uniform(0.7, 1.3) * c["gain"]).clip(0, 255)
    img = 255 * (img / 255) ** c["gamma"] + c["offset"] + rng.normal(0, 8, (h, w, 3))
    return img.clip(0, 255).astype(np.uint8)

def make_set(rng, n_ids=50, n_gallery=2):
    shirts, trousers = rng.integers(20, 236, (n_ids, 3)), rng.integers(20, 236, (n_ids, 3))
    query = np.array([make_person_hard(rng, shirts[i], trousers[i], "A") for i in range(n_ids)])
    gallery = np.array([make_person_hard(rng, shirts[i], trousers[i], "B") for i in range(n_ids) for _ in range(n_gallery)])
    return query, np.arange(n_ids), gallery, np.repeat(np.arange(n_ids), n_gallery)

def evaluate(D, q_ids, g_ids):
    order = np.argsort(D, axis=1, kind="stable")
    matches = g_ids[order] == q_ids[:, None]
    first = matches.argmax(axis=1)
    aps = [np.mean(np.arange(1, m.sum() + 1) / (np.flatnonzero(m) + 1)) for m in matches]
    return float(np.mean(first < 1)), float(np.mean(first < 5)), float(np.mean(aps))

def hsv_hist(img, bins=(12, 4)):
    hsv = cv2.cvtColor(img, cv2.COLOR_RGB2HSV)
    feats = []
    for a, b in [(0, 16), (16, 38), (38, 64)]:
        h = cv2.calcHist([np.ascontiguousarray(hsv[a:b])], [0, 1], None, list(bins), [0, 180, 0, 256]).ravel()
        feats.append(np.sqrt(h / h.sum()))
    return np.concatenate(feats)

def learn_btf(A, B):
    """Brightness transfer function camera B -> camera A, one lookup table per channel, learned by matching
    the pooled intensity distributions of training crops of the same people seen by both cameras."""
    lut = np.zeros((3, 256), np.uint8)
    for c in range(3):
        a, b = A[..., c].ravel(), np.sort(B[..., c].ravel())
        cdf_b = np.searchsorted(b, np.arange(256), side="right") / len(b)
        lut[c] = np.quantile(a, cdf_b).round().clip(0, 255)
    return lut

def apply_btf(img, lut):
    return np.stack([lut[c][img[..., c]] for c in range(3)], axis=-1)

def dist(fq, fg):
    return np.linalg.norm(fq[:, None] - fg[None], axis=2)

rng = np.random.default_rng(0)
query, q_ids, gallery, g_ids = make_set(rng)
tq, tg = q_ids >= 25, g_ids >= 25
lut = learn_btf(query[~tq], gallery[~tg])
Fq = np.array([hsv_hist(im) for im in query[tq]])
Fg = np.array([hsv_hist(im) for im in gallery[tg]]); Fg_btf = np.array([hsv_hist(apply_btf(im, lut)) for im in gallery[tg]])

drng = np.random.default_rng(99)                                      # 1,000 strangers, camera B only
d_shirts, d_trousers = drng.integers(20, 236, (1000, 3)), drng.integers(20, 236, (1000, 3))
D_imgs = [make_person_hard(drng, d_shirts[i], d_trousers[i], "B") for i in range(1000)]
Fd = np.array([hsv_hist(im) for im in D_imgs]); Fd_btf = np.array([hsv_hist(apply_btf(im, lut)) for im in D_imgs])

print("distractors  gallery |  HSV: rank-1  mAP | BTF + HSV: rank-1  mAP")
for n in [0, 50, 200, 1000]:
    gid = np.concatenate([g_ids[tg], np.full(n, -1)])
    a = evaluate(dist(Fq, np.vstack([Fg, Fd[:n]])), q_ids[tq], gid)
    b = evaluate(dist(Fq, np.vstack([Fg_btf, Fd_btf[:n]])), q_ids[tq], gid)
    print(f"{n:11d}  {n + len(Fg):7d} |       {a[0]:.3f}  {a[2]:.3f} |            {b[0]:.3f}  {b[2]:.3f}")
distractors  gallery |  HSV: rank-1  mAP | BTF + HSV: rank-1  mAP
          0       50 |       0.760  0.805 |            0.960  0.970
         50      100 |       0.680  0.699 |            0.920  0.951
        200      250 |       0.440  0.543 |            0.840  0.899
       1000     1050 |       0.200  0.331 |            0.720  0.787

Every method loses as the gallery fills with strangers. The HSV baseline falls from mAP 0.805 to 0.331 with 1,000 distractors, and its rank-1 from 0.760 to 0.200: four in five searches now show a stranger first. The BTF version degrades more gracefully (mAP 0.970 to 0.787, rank-1 0.960 to 0.720), because correcting the camera keeps the true matches closer than most lookalikes. A site with thousands of passers-by per hour has galleries far larger than 1,050, so the rank-1 a human operator experiences is much lower than any small-gallery benchmark suggests. Report the curve, not the point at zero distractors.

Error analysis

Look at the queries the best method still gets wrong before changing the method again. Typical causes in this data, and their real-world counterparts:

Cause How to find it here Real-world counterpart
Occluder covers the legs the query or both gallery crops had an occluder bags, crowds, street furniture
Lookalike clothing the rank-1 wrong match has a similar shirt and trouser colour uniforms, dark winter clothes
Camera tone curve errors concentrate on very light or very dark clothes different sensors, auto-exposure
Misalignment large shift moves the torso into the head stripe detector boxes of varying tightness

Print, for each failed query, its id, the id of the wrong rank-1 match and the two shirt colours; you will usually find that the confusions are explainable, which tells you which feature to add.

Your turn

  1. Add a fourth stripe split (head, upper torso, lower torso, legs) or more hue bins. Does test mAP improve? Choose the setting using the training identities only (for example by evaluating on them with leave-some-identities-out), then report it once on the test identities.
Hint

Split the 25 training identities into 15 for fitting LDA and 10 for validation; choose stripes and bins on those 10; refit on all 25; evaluate once on identities 25 to 49.

  1. Re-ranking: implement query expansion (average the query feature with its top-2 gallery features, renormalise, search again). Measure mAP with 0 and 1,000 distractors.
Hint

Query expansion helps when the top matches are right and hurts when they are wrong, so its gain shrinks (or turns negative) with many distractors. Report both.

  1. What would change if query and gallery came from the same camera?
Answer

The camera shift disappears, so colour features become much stronger and scores rise; but such matches are near-duplicates of the query's own track and say nothing about cross-camera search. Benchmarks therefore exclude same-camera, same-identity gallery images from the evaluation.

Write-up template

Section Content
Purpose what the search is for (e.g. finding a lost child), who may run a query, and what it must not be used for
Data cameras, identities, crops per identity, how ids were labelled; split by identity (train / test ids)
Methods features, normalisation, metric learning, distance
Results rank-1, rank-5, mAP on test ids (table); the distractor curve
Errors failure causes with counts and examples
Legal basis and DPIA lawful basis (e.g. legitimate interest or a specific legal duty), the impact assessment, signage
Minimisation and retention features instead of images where possible, deletion after N days, no linking to names unless required
Access and logging who can search, every query logged and reviewable
Bias and limits groups or clothing types with lower accuracy, clothes changes, crowds; synthetic-data caveat

Test yourself

Why are identities 25 to 49 kept out of everything except the final evaluation?

  1. They are harder
  2. The learned metric must be tested on people it has never seen; fitting on them (the leak row) inflates the scores
  3. LDA cannot handle 50 classes
  4. To make the gallery smaller

As distractors are added to the gallery, rank-1 and mAP ...

  1. stay the same, because the queries did not change
  2. fall, because every stranger is another chance for a lookalike to outrank the true match
  3. rise, because there is more data
  4. become undefined

Which statement belongs in the privacy section of a re-ID write-up?

  1. The model is accurate, so privacy is not a concern
  2. Who may run searches, the legal basis, the retention period of gallery features, and that every query is logged
  3. The images are synthetic, so no rules apply to the deployed system
  4. Re-ID does not process personal data because it uses no names