MCPcopy Create free account
hub / github.com/XLearning-SCU/2022-CVPR-DART / eval_sysu

Function eval_sysu

eval_metrics.py:6–82  ·  view source on GitHub ↗

Evaluation with sysu metric Key: for each query identity, its gallery images from the same camera view are discarded. "Following the original setting in ite dataset"

(distmat, q_pids, g_pids, q_camids, g_camids, max_rank = 20)

Source from the content-addressed store, hash-verified

4import pdb
5
6def eval_sysu(distmat, q_pids, g_pids, q_camids, g_camids, max_rank = 20):
7 """Evaluation with sysu metric
8 Key: for each query identity, its gallery images from the same camera view are discarded. "Following the original setting in ite dataset"
9 """
10 num_q, num_g = distmat.shape
11 if num_g < max_rank:
12 max_rank = num_g
13 print("Note: number of gallery samples is quite small, got {}".format(num_g))
14 indices = np.argsort(distmat, axis=1)
15 pred_label = g_pids[indices]
16 matches = (g_pids[indices] == q_pids[:, np.newaxis]).astype(np.int32)
17
18 # compute cmc curve for each query
19 new_all_cmc = []
20 all_cmc = []
21 all_AP = []
22 all_INP = []
23 num_valid_q = 0. # number of valid query
24 for q_idx in range(num_q):
25 # get query pid and camid
26 q_pid = q_pids[q_idx]
27 q_camid = q_camids[q_idx]
28
29 # remove gallery samples that have the same pid and camid with query
30 order = indices[q_idx]
31 remove = (q_camid == 3) & (g_camids[order] == 2)
32 keep = np.invert(remove)
33
34 # compute cmc curve
35 # the cmc calculation is different from standard protocol
36 # we follow the protocol of the author's released code
37 new_cmc = pred_label[q_idx][keep]
38 new_index = np.unique(new_cmc, return_index=True)[1]
39 new_cmc = [new_cmc[index] for index in sorted(new_index)]
40
41 new_match = (new_cmc == q_pid).astype(np.int32)
42 new_cmc = new_match.cumsum()
43 new_all_cmc.append(new_cmc[:max_rank])
44
45 orig_cmc = matches[q_idx][keep] # binary vector, positions with value 1 are correct matches
46 if not np.any(orig_cmc):
47 # this condition is true when query identity does not appear in gallery
48 continue
49
50 cmc = orig_cmc.cumsum()
51
52 # compute mINP
53 # refernece Deep Learning for Person Re-identification: A Survey and Outlook
54 pos_idx = np.where(orig_cmc == 1)
55 pos_max_idx = np.max(pos_idx)
56 inp = cmc[pos_max_idx]/ (pos_max_idx + 1.0)
57 all_INP.append(inp)
58
59 cmc[cmc > 1] = 1
60
61 all_cmc.append(cmc[:max_rank])
62 num_valid_q += 1.
63

Callers 2

testFunction · 0.90
test.pyFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected