(features_path, output_path, show_num_identities_for_each_domain, plot_by_domain=False, if_from_numpy='',
if_generalization=False)
| 386 | |
| 387 | |
| 388 | def visualize(features_path, output_path, show_num_identities_for_each_domain, plot_by_domain=False, if_from_numpy='', |
| 389 | if_generalization=False): |
| 390 | from collections import defaultdict |
| 391 | datasets = defaultdict(dict) |
| 392 | if not osp.exists(features_path): |
| 393 | assert False, f'features_path ({features_path}) is not existing!' |
| 394 | query_dict_list, gallery_dict_list = [], [] |
| 395 | for _file in sorted(os.listdir(features_path)): |
| 396 | print(_file) |
| 397 | if 'cids' in _file or 'fuse' in _file: |
| 398 | continue |
| 399 | features = np.load(osp.join(features_path, _file)) |
| 400 | dataset_name = re.findall(p1, _file)[0] |
| 401 | if 'pids' in _file: |
| 402 | if 'pids' in datasets[dataset_name].keys(): |
| 403 | datasets[dataset_name]['pids'] = np.concatenate( |
| 404 | (datasets[dataset_name]['pids'], features), axis=0) |
| 405 | # print(f'{dataset_name} ==> add pids: {features.shape}') |
| 406 | else: |
| 407 | datasets[dataset_name].update({'pids': features}) |
| 408 | # print(f'{dataset_name} ==> initial pids: {features.shape}') |
| 409 | |
| 410 | elif 'features' in _file: |
| 411 | if 'features' in datasets[dataset_name].keys(): |
| 412 | datasets[dataset_name]['features'] = np.concatenate( |
| 413 | (datasets[dataset_name]['features'], features), axis=0) |
| 414 | # print(f'{dataset_name} ==> add features: {features.shape}') |
| 415 | else: |
| 416 | datasets[dataset_name].update({'features': features}) |
| 417 | # print(f'{dataset_name} ==> initial features: {features.shape}') |
| 418 | elif 'paths' in _file: |
| 419 | if 'paths' in datasets[dataset_name].keys(): |
| 420 | datasets[dataset_name]['paths'] = np.concatenate( |
| 421 | (datasets[dataset_name]['paths'], features), axis=0) |
| 422 | # print(f'{dataset_name} ==> add features: {features.shape}') |
| 423 | else: |
| 424 | datasets[dataset_name].update({'paths': features}) |
| 425 | # print(f'{dataset_name} ==> initial features: {features.shape}') |
| 426 | elif 'meta_graph_vertex' in _file: |
| 427 | meta_graph_vertex = features |
| 428 | else: |
| 429 | assert False, f'the name of _file is {_file}, which is not compatible' |
| 430 | assert meta_graph_vertex is not None |
| 431 | print(f'meta_graph_vertex is <{meta_graph_vertex.shape}>!') |
| 432 | print(list(datasets.keys())) |
| 433 | for k, v in datasets.items(): |
| 434 | # print(k) |
| 435 | # print(np.max(v['pids'])) |
| 436 | # print(np.min(v['pids'])) |
| 437 | v['pids'] = relabel_numpy(v['pids']) |
| 438 | # print(np.max(v['pids'])) |
| 439 | # print(np.min(v['pids'])) |
| 440 | |
| 441 | for k, v in datasets.items(): |
| 442 | selected_ids = np.random.permutation(np.max(v['pids']))[ |
| 443 | :show_num_identities_for_each_domain] |
| 444 | print(f'selected id for {k} is : {selected_ids}') |
| 445 |
no test coverage detected