Reorganize multi-frame feature extraction results into individual feature sequences. Args: extracted_features (List[List[Dict]]): Multi-frame feature extraction results stored in a nested list. Each element of the outer list is the feature extraction results
(extracted_features,
with_track_id=True,
target_frame=0)
| 434 | |
| 435 | |
| 436 | def _collate_feature_sequence(extracted_features, |
| 437 | with_track_id=True, |
| 438 | target_frame=0): |
| 439 | """Reorganize multi-frame feature extraction results into individual |
| 440 | feature sequences. |
| 441 | |
| 442 | Args: |
| 443 | extracted_features (List[List[Dict]]): Multi-frame feature extraction |
| 444 | results stored in a nested list. Each element of the outer list |
| 445 | is the feature extraction results of a single frame, and each |
| 446 | element of the inner list is the extracted results of one person, |
| 447 | which contains: |
| 448 | features (ndarray): extracted features |
| 449 | track_id (int): unique id of each person, required when |
| 450 | ``with_track_id==True``` |
| 451 | with_track_id (bool): If True, the element in pose_results is expected |
| 452 | to contain "track_id", which will be used to gather the pose |
| 453 | sequence of a person from multiple frames. Otherwise, the pose |
| 454 | results in each frame are expected to have a consistent number and |
| 455 | order of identities. Default is True. |
| 456 | target_frame (int): The index of the target frame. Default: 0. |
| 457 | """ |
| 458 | T = len(extracted_features) |
| 459 | assert T > 0 |
| 460 | |
| 461 | target_frame = (T + target_frame) % T # convert negative index to positive |
| 462 | |
| 463 | N = len( |
| 464 | extracted_features[target_frame]) # use identities in the target frame |
| 465 | if N == 0: |
| 466 | return [] |
| 467 | |
| 468 | C = extracted_features[target_frame][0]['features'].shape[0] |
| 469 | |
| 470 | track_ids = None |
| 471 | if with_track_id: |
| 472 | track_ids = [ |
| 473 | res['track_id'] for res in extracted_features[target_frame] |
| 474 | ] |
| 475 | |
| 476 | feature_sequences = [] |
| 477 | for idx in range(N): |
| 478 | feature_seq = dict() |
| 479 | # gather static information |
| 480 | for k, v in extracted_features[target_frame][idx].items(): |
| 481 | if k != 'features': |
| 482 | feature_seq[k] = v |
| 483 | # gather keypoints |
| 484 | if not with_track_id: |
| 485 | feature_seq['features'] = np.stack( |
| 486 | [frame[idx]['features'] for frame in extracted_features]) |
| 487 | else: |
| 488 | features = np.zeros((T, C), dtype=np.float32) |
| 489 | features[target_frame] = extracted_features[target_frame][idx][ |
| 490 | 'features'] |
| 491 | # find the left most frame containing track_ids[idx] |
| 492 | for frame_idx in range(target_frame - 1, -1, -1): |
| 493 | contains_idx = False |
no test coverage detected