Convert keypoints following the mapping correspondence between src and dst keypoints definition. Supported conventions by now: agora, coco, smplx, smpl, mpi_inf_3dhp, mpi_inf_3dhp_test, h36m, h36m_mmpose, pw3d, mpii, lsp. Args: keypoints [Union[np.ndarray, torch.Tensor]]: input k
(
keypoints: Union[np.ndarray, torch.Tensor],
src: str,
dst: str,
approximate: bool = False,
mask: Union[np.ndarray, torch.Tensor] = None,
keypoints_factory: dict = KEYPOINTS_FACTORY,
return_mask: bool = True
)
| 83 | |
| 84 | |
| 85 | def convert_kps( |
| 86 | keypoints: Union[np.ndarray, torch.Tensor], |
| 87 | src: str, |
| 88 | dst: str, |
| 89 | approximate: bool = False, |
| 90 | mask: Union[np.ndarray, torch.Tensor] = None, |
| 91 | keypoints_factory: dict = KEYPOINTS_FACTORY, |
| 92 | return_mask: bool = True |
| 93 | ) -> Tuple[Union[np.ndarray, torch.Tensor], Union[np.ndarray, torch.Tensor]]: |
| 94 | """Convert keypoints following the mapping correspondence between src and |
| 95 | dst keypoints definition. Supported conventions by now: agora, coco, smplx, |
| 96 | smpl, mpi_inf_3dhp, mpi_inf_3dhp_test, h36m, h36m_mmpose, pw3d, mpii, lsp. |
| 97 | Args: |
| 98 | keypoints [Union[np.ndarray, torch.Tensor]]: input keypoints array, |
| 99 | could be (f * n * J * 3/2) or (f * J * 3/2). |
| 100 | You can set keypoints as np.zeros((1, J, 2)) |
| 101 | if you only need mask. |
| 102 | src (str): source data type from keypoints_factory. |
| 103 | dst (str): destination data type from keypoints_factory. |
| 104 | approximate (bool): control whether approximate mapping is allowed. |
| 105 | mask (Union[np.ndarray, torch.Tensor], optional): |
| 106 | The original mask to mark the existence of the keypoints. |
| 107 | None represents all ones mask. |
| 108 | Defaults to None. |
| 109 | keypoints_factory (dict, optional): A class to store the attributes. |
| 110 | Defaults to keypoints_factory. |
| 111 | return_mask (bool, optional): whether to return a mask as part of the |
| 112 | output. It is unnecessary to return a mask if the keypoints consist |
| 113 | of confidence. Any invalid keypoints will have zero confidence. |
| 114 | Defaults to True. |
| 115 | Returns: |
| 116 | Tuple[Union[np.ndarray, torch.Tensor], Union[np.ndarray, torch.Tensor]] |
| 117 | : tuple of (out_keypoints, mask). out_keypoints and mask will be of |
| 118 | the same type. |
| 119 | """ |
| 120 | assert keypoints.ndim in {3, 4} |
| 121 | if isinstance(keypoints, torch.Tensor): |
| 122 | |
| 123 | def new_array_func(shape, value, device_data, if_uint8): |
| 124 | if if_uint8: |
| 125 | dtype = torch.uint8 |
| 126 | else: |
| 127 | dtype = None |
| 128 | if value == 1: |
| 129 | return torch.ones(size=shape, |
| 130 | dtype=dtype, |
| 131 | device=device_data.device) |
| 132 | elif value == 0: |
| 133 | return torch.zeros(size=shape, |
| 134 | dtype=dtype, |
| 135 | device=device_data.device) |
| 136 | else: |
| 137 | raise ValueError |
| 138 | |
| 139 | def to_type_uint8_func(data): |
| 140 | return data.to(dtype=torch.uint8) |
| 141 | |
| 142 | elif isinstance(keypoints, np.ndarray): |
no test coverage detected