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

Function _taylor

tools/preprocess/pose2d_utils.py:605–634  ·  view source on GitHub ↗

Distribution aware coordinate decoding method. Note: - heatmap height: H - heatmap width: W Args: heatmap (np.ndarray[H, W]): Heatmap of a particular joint type. coord (np.ndarray[2,]): Coordinates of the predicted keypoints. Returns: np.ndarray

(heatmap, coord)

Source from the content-addressed store, hash-verified

603
604
605def _taylor(heatmap, coord):
606 """Distribution aware coordinate decoding method.
607
608 Note:
609 - heatmap height: H
610 - heatmap width: W
611
612 Args:
613 heatmap (np.ndarray[H, W]): Heatmap of a particular joint type.
614 coord (np.ndarray[2,]): Coordinates of the predicted keypoints.
615
616 Returns:
617 np.ndarray[2,]: Updated coordinates.
618 """
619 H, W = heatmap.shape[:2]
620 px, py = int(coord[0]), int(coord[1])
621 if 1 < px < W - 2 and 1 < py < H - 2:
622 dx = 0.5 * (heatmap[py][px + 1] - heatmap[py][px - 1])
623 dy = 0.5 * (heatmap[py + 1][px] - heatmap[py - 1][px])
624 dxx = 0.25 * (heatmap[py][px + 2] - 2 * heatmap[py][px] + heatmap[py][px - 2])
625 dxy = 0.25 * (heatmap[py + 1][px + 1] - heatmap[py - 1][px + 1] - heatmap[py + 1][px - 1] + heatmap[py - 1][px - 1])
626 dyy = 0.25 * (heatmap[py + 2 * 1][px] - 2 * heatmap[py][px] + heatmap[py - 2 * 1][px])
627 derivative = np.array([[dx], [dy]])
628 hessian = np.array([[dxx, dxy], [dxy, dyy]])
629 if dxx * dyy - dxy**2 != 0:
630 hessianinv = np.linalg.inv(hessian)
631 offset = -hessianinv @ derivative
632 offset = np.squeeze(np.array(offset.T), axis=0)
633 coord += offset
634 return coord
635
636
637def post_dark_udp(coords, batch_heatmaps, kernel=3):

Callers 1

keypoints_from_heatmapsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected