MCPcopy Create free account
hub / github.com/ModelTC/LightX2V / transform_preds

Function transform_preds

tools/preprocess/pose2d_utils.py:275–319  ·  view source on GitHub ↗

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

(coords, center, scale, output_size, use_udp=False)

Source from the content-addressed store, hash-verified

273
274
275def transform_preds(coords, center, scale, output_size, use_udp=False):
276 """Get final keypoint predictions from heatmaps and apply scaling and
277 translation to map them back to the image.
278
279 Note:
280 num_keypoints: K
281
282 Args:
283 coords (np.ndarray[K, ndims]):
284
285 * If ndims=2, corrds are predicted keypoint location.
286 * If ndims=4, corrds are composed of (x, y, scores, tags)
287 * If ndims=5, corrds are composed of (x, y, scores, tags,
288 flipped_tags)
289
290 center (np.ndarray[2, ]): Center of the bounding box (x, y).
291 scale (np.ndarray[2, ]): Scale of the bounding box
292 wrt [width, height].
293 output_size (np.ndarray[2, ] | list(2,)): Size of the
294 destination heatmaps.
295 use_udp (bool): Use unbiased data processing
296
297 Returns:
298 np.ndarray: Predicted coordinates in the images.
299 """
300 assert coords.shape[1] in (2, 4, 5)
301 assert len(center) == 2
302 assert len(scale) == 2
303 assert len(output_size) == 2
304
305 # Recover the scale which is normalized by a factor of 200.
306 # scale = scale * 200.0
307
308 if use_udp:
309 scale_x = scale[0] / (output_size[0] - 1.0)
310 scale_y = scale[1] / (output_size[1] - 1.0)
311 else:
312 scale_x = scale[0] / output_size[0]
313 scale_y = scale[1] / output_size[1]
314
315 target_coords = np.ones_like(coords)
316 target_coords[:, 0] = coords[:, 0] * scale_x + center[0] - scale[0] * 0.5
317 target_coords[:, 1] = coords[:, 1] * scale_y + center[1] - scale[1] * 0.5
318
319 return target_coords
320
321
322def _calc_distances(preds, targets, mask, normalize):

Callers 3

keypoints_from_heatmapsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected