MCPcopy
hub / github.com/thuml/Transfer-Learning-Library / evaluate_all

Function evaluate_all

tllib/utils/metric/reid.py:233–256  ·  view source on GitHub ↗

Compute CMC score, mAP and return

(dist_mat, query, gallery, cmc_topk=(1, 5, 10), cmc_flag=False)

Source from the content-addressed store, hash-verified

231
232
233def evaluate_all(dist_mat, query, gallery, cmc_topk=(1, 5, 10), cmc_flag=False):
234 """Compute CMC score, mAP and return"""
235 query_ids = [pid for _, pid, _ in query]
236 gallery_ids = [pid for _, pid, _ in gallery]
237 query_cams = [cid for _, _, cid in query]
238 gallery_cams = [cid for _, _, cid in gallery]
239
240 # Compute mean AP
241 mAP = mean_ap(dist_mat, query_ids, gallery_ids, query_cams, gallery_cams)
242 print('Mean AP: {:4.1%}'.format(mAP))
243
244 if not cmc_flag:
245 return mAP
246
247 cmc_configs = {
248 'config': dict(separate_camera_set=False, single_gallery_shot=False, first_match_break=True)
249 }
250 cmc_scores = {name: cmc(dist_mat, query_ids, gallery_ids, query_cams, gallery_cams, **params) for name, params in
251 cmc_configs.items()}
252
253 print('CMC Scores:')
254 for k in cmc_topk:
255 print(' top-{:<4}{:12.1%}'.format(k, cmc_scores['config'][k - 1]))
256 return cmc_scores['config'][0], mAP
257
258
259def validate(val_loader, model, query, gallery, device, criterion='cosine', cmc_flag=False, rerank=False):

Callers 1

validateFunction · 0.85

Calls 3

mean_apFunction · 0.85
cmcFunction · 0.85
formatMethod · 0.80

Tested by

no test coverage detected