(val_loader, model, query, gallery, device, criterion='cosine', cmc_flag=False, rerank=False)
| 257 | |
| 258 | |
| 259 | def validate(val_loader, model, query, gallery, device, criterion='cosine', cmc_flag=False, rerank=False): |
| 260 | assert criterion in ['cosine', 'euclidean'] |
| 261 | # when criterion == 'cosine', normalize feature of single image into unit norm |
| 262 | normalize = (criterion == 'cosine') |
| 263 | |
| 264 | feature_dict = extract_reid_feature(val_loader, model, device, normalize) |
| 265 | dist_mat = pairwise_distance(feature_dict, query, gallery) |
| 266 | results = evaluate_all(dist_mat, query=query, gallery=gallery, cmc_flag=cmc_flag) |
| 267 | if not rerank: |
| 268 | return results |
| 269 | # apply person re-ranking |
| 270 | print('Applying person re-ranking') |
| 271 | dist_mat_query = pairwise_distance(feature_dict, query, query) |
| 272 | dist_mat_gallery = pairwise_distance(feature_dict, gallery, gallery) |
| 273 | dist_mat = re_ranking(dist_mat, dist_mat_query, dist_mat_gallery) |
| 274 | return evaluate_all(dist_mat, query=query, gallery=gallery, cmc_flag=cmc_flag) |
| 275 | |
| 276 | |
| 277 | # location parameters for visualization |
no test coverage detected