Get final keypoint predictions from heatmaps and apply scaling and translation to map them back to the image. Note: num_keypoints: K Args: coords (np.ndarray[K, ndims]): * If ndims=2, corrds are predicted keypoint location. * If ndims=4, corrds are
(coords, center, scale, output_size, use_udp=False)
| 147 | |
| 148 | |
| 149 | def transform_preds(coords, center, scale, output_size, use_udp=False): |
| 150 | """Get final keypoint predictions from heatmaps and apply scaling and |
| 151 | translation to map them back to the image. |
| 152 | Note: |
| 153 | num_keypoints: K |
| 154 | Args: |
| 155 | coords (np.ndarray[K, ndims]): |
| 156 | * If ndims=2, corrds are predicted keypoint location. |
| 157 | * If ndims=4, corrds are composed of (x, y, scores, tags) |
| 158 | * If ndims=5, corrds are composed of (x, y, scores, tags, |
| 159 | flipped_tags) |
| 160 | center (np.ndarray[2, ]): Center of the bounding box (x, y). |
| 161 | scale (np.ndarray[2, ]): Scale of the bounding box |
| 162 | wrt [width, height]. |
| 163 | output_size (np.ndarray[2, ] | list(2,)): Size of the |
| 164 | destination heatmaps. |
| 165 | use_udp (bool): Use unbiased data processing |
| 166 | Returns: |
| 167 | np.ndarray: Predicted coordinates in the images. |
| 168 | """ |
| 169 | assert coords.shape[1] in (2, 4, 5) |
| 170 | assert len(center) == 2 |
| 171 | assert len(scale) == 2 |
| 172 | assert len(output_size) == 2 |
| 173 | |
| 174 | # Recover the scale which is normalized by a factor of 200. |
| 175 | scale = scale * 200.0 |
| 176 | |
| 177 | if use_udp: |
| 178 | scale_x = scale[0] / (output_size[0] - 1.0) |
| 179 | scale_y = scale[1] / (output_size[1] - 1.0) |
| 180 | else: |
| 181 | scale_x = scale[0] / output_size[0] |
| 182 | scale_y = scale[1] / output_size[1] |
| 183 | |
| 184 | target_coords = np.ones_like(coords) |
| 185 | target_coords[:, 0] = coords[:, 0] * scale_x + center[0] - scale[0] * 0.5 |
| 186 | target_coords[:, 1] = coords[:, 1] * scale_y + center[1] - scale[1] * 0.5 |
| 187 | |
| 188 | return target_coords |
| 189 | |
| 190 | |
| 191 | def get_affine_transform(center, |
no outgoing calls
no test coverage detected