MCPcopy Create free account
hub / github.com/OpenGVLab/HumanBench / R1_mAP_eval

Class R1_mAP_eval

PATH/core/testers/utils/metrics.py:90–133  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

88
89
90class R1_mAP_eval():
91 def __init__(self, num_query, max_rank=50, feat_norm=True, reranking=False):
92 super(R1_mAP_eval, self).__init__()
93 self.num_query = num_query
94 self.max_rank = max_rank
95 self.feat_norm = feat_norm
96 self.reranking = reranking
97
98 def reset(self):
99 self.feats = []
100 self.pids = []
101 self.camids = []
102
103 def update(self, output): # called once for each batch
104 feat, pid, camid = output
105 self.feats.append(feat.cpu())
106 self.pids.extend(np.asarray(pid))
107 self.camids.extend(np.asarray(camid))
108
109 def compute(self): # called after each epoch
110 feats = torch.cat(self.feats, dim=0)
111 if self.feat_norm:
112 print("The test feature is normalized")
113 feats = torch.nn.functional.normalize(feats, dim=1, p=2) # along channel
114 # query
115 qf = feats[:self.num_query]
116 q_pids = np.asarray(self.pids[:self.num_query])
117 q_camids = np.asarray(self.camids[:self.num_query])
118 # gallery
119 gf = feats[self.num_query:]
120 g_pids = np.asarray(self.pids[self.num_query:])
121
122 g_camids = np.asarray(self.camids[self.num_query:])
123 if self.reranking:
124 print('=> Enter reranking')
125 # distmat = re_ranking(qf, gf, k1=20, k2=6, lambda_value=0.3)
126 distmat = re_ranking(qf, gf, k1=50, k2=15, lambda_value=0.3)
127
128 else:
129 print('=> Computing DistMat with euclidean_distance')
130 distmat = euclidean_distance(qf, gf)
131 cmc, mAP = eval_func(distmat, q_pids, g_pids, q_camids, g_camids)
132
133 return cmc, mAP, distmat, self.pids, self.camids, qf, gf

Callers 1

runMethod · 0.85

Calls

no outgoing calls

Tested by 1

runMethod · 0.68