MCPcopy Create free account
hub / github.com/OpenGVLab/HumanBench / _taylor

Function _taylor

PATH/core/models/decoders/pose_decodes/pose_decoder.py:132–166  ·  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[2,]

(heatmap, coord)

Source from the content-addressed store, hash-verified

130
131
132def _taylor(heatmap, coord):
133 """Distribution aware coordinate decoding method.
134
135 Note:
136 heatmap height: H
137 heatmap width: W
138
139 Args:
140 heatmap (np.ndarray[H, W]): Heatmap of a particular joint type.
141 coord (np.ndarray[2,]): Coordinates of the predicted keypoints.
142
143 Returns:
144 np.ndarray[2,]: Updated coordinates.
145 """
146 H, W = heatmap.shape[:2]
147 px, py = int(coord[0]), int(coord[1])
148 if 1 < px < W - 2 and 1 < py < H - 2:
149 dx = 0.5 * (heatmap[py][px + 1] - heatmap[py][px - 1])
150 dy = 0.5 * (heatmap[py + 1][px] - heatmap[py - 1][px])
151 dxx = 0.25 * (
152 heatmap[py][px + 2] - 2 * heatmap[py][px] + heatmap[py][px - 2])
153 dxy = 0.25 * (
154 heatmap[py + 1][px + 1] - heatmap[py - 1][px + 1] -
155 heatmap[py + 1][px - 1] + heatmap[py - 1][px - 1])
156 dyy = 0.25 * (
157 heatmap[py + 2 * 1][px] - 2 * heatmap[py][px] +
158 heatmap[py - 2 * 1][px])
159 derivative = np.array([[dx], [dy]])
160 hessian = np.array([[dxx, dxy], [dxy, dyy]])
161 if dxx * dyy - dxy**2 != 0:
162 hessianinv = np.linalg.inv(hessian)
163 offset = -hessianinv @ derivative
164 offset = np.squeeze(np.array(offset.T), axis=0)
165 coord += offset
166 return coord
167
168
169def post_dark_udp(coords, batch_heatmaps, kernel=3):

Callers 2

keypoints_from_heatmapsFunction · 0.85
keypoints_from_heatmapsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected