Flip human joints horizontally. Note: batch_size: N num_keypoint: K Args: regression (np.ndarray([..., K, C])): Coordinates of keypoints, where K is the joint number and C is the dimension. Example shapes are: - [N, K, C]: a batch of keypoints
(regression,
flip_pairs,
center_mode='static',
center_x=0.5,
center_index=0)
| 51 | |
| 52 | |
| 53 | def fliplr_regression(regression, |
| 54 | flip_pairs, |
| 55 | center_mode='static', |
| 56 | center_x=0.5, |
| 57 | center_index=0): |
| 58 | """Flip human joints horizontally. |
| 59 | |
| 60 | Note: |
| 61 | batch_size: N |
| 62 | num_keypoint: K |
| 63 | Args: |
| 64 | regression (np.ndarray([..., K, C])): Coordinates of keypoints, where K |
| 65 | is the joint number and C is the dimension. Example shapes are: |
| 66 | - [N, K, C]: a batch of keypoints where N is the batch size. |
| 67 | - [N, T, K, C]: a batch of pose sequences, where T is the frame |
| 68 | number. |
| 69 | flip_pairs (list[tuple()]): Pairs of keypoints which are mirrored |
| 70 | (for example, left ear -- right ear). |
| 71 | center_mode (str): The mode to set the center location on the x-axis |
| 72 | to flip around. Options are: |
| 73 | - static: use a static x value (see center_x also) |
| 74 | - root: use a root joint (see center_index also) |
| 75 | center_x (float): Set the x-axis location of the flip center. Only used |
| 76 | when center_mode=static. |
| 77 | center_index (int): Set the index of the root joint, whose x location |
| 78 | will be used as the flip center. Only used when center_mode=root. |
| 79 | |
| 80 | Returns: |
| 81 | tuple: Flipped human joints. |
| 82 | |
| 83 | - regression_flipped (np.ndarray([..., K, C])): Flipped joints. |
| 84 | """ |
| 85 | assert regression.ndim >= 2, f'Invalid pose shape {regression.shape}' |
| 86 | |
| 87 | allowed_center_mode = {'static', 'root'} |
| 88 | assert center_mode in allowed_center_mode, 'Get invalid center_mode ' \ |
| 89 | f'{center_mode}, allowed choices are {allowed_center_mode}' |
| 90 | |
| 91 | if center_mode == 'static': |
| 92 | x_c = center_x |
| 93 | elif center_mode == 'root': |
| 94 | assert regression.shape[-2] > center_index |
| 95 | x_c = regression[..., center_index:center_index + 1, 0] |
| 96 | |
| 97 | regression_flipped = regression.copy() |
| 98 | # Swap left-right parts |
| 99 | for left, right in flip_pairs: |
| 100 | regression_flipped[..., left, :] = regression[..., right, :] |
| 101 | regression_flipped[..., right, :] = regression[..., left, :] |
| 102 | |
| 103 | # Flip horizontally |
| 104 | regression_flipped[..., 0] = x_c * 2 - regression_flipped[..., 0] |
| 105 | return regression_flipped |
| 106 | |
| 107 | |
| 108 | def flip_back(output_flipped, flip_pairs, target_type='GaussianHeatMap'): |
nothing calls this directly
no outgoing calls
no test coverage detected