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

Class ViTPose

tools/preprocess/pose2d.py:305–334  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

303
304
305class ViTPose(SimpleOnnxInference):
306 def __init__(self, checkpoint, device="cuda", **kwargs):
307 super(ViTPose, self).__init__(checkpoint, device=device)
308
309 def forward(self, img, center, scale, **kwargs):
310 heatmaps = self.session.run([], {self.session.get_inputs()[0].name: img})[0]
311 points, prob = keypoints_from_heatmaps(heatmaps=heatmaps, center=center, scale=scale * 200, unbiased=True, use_udp=False)
312 return np.concatenate([points, prob], axis=2)
313
314 @staticmethod
315 def preprocess(img, bbox=None, input_resolution=(256, 192), rescale=1.25, mask=None, **kwargs):
316 if bbox is None or bbox[-1] <= 0 or (bbox[2] - bbox[0]) < 10 or (bbox[3] - bbox[1]) < 10:
317 bbox = np.array([0, 0, img.shape[1], img.shape[0]])
318
319 bbox_xywh = bbox
320 if mask is not None:
321 img = np.where(mask > 128, img, mask)
322
323 if isinstance(input_resolution, int):
324 center, scale = bbox_from_detector(bbox_xywh, (input_resolution, input_resolution), rescale=rescale)
325 img, new_shape, old_xy, new_xy = crop(img, center, scale, (input_resolution, input_resolution))
326 else:
327 center, scale = bbox_from_detector(bbox_xywh, input_resolution, rescale=rescale)
328 img, new_shape, old_xy, new_xy = crop(img, center, scale, (input_resolution[0], input_resolution[1]))
329
330 IMG_NORM_MEAN = np.array([0.485, 0.456, 0.406])
331 IMG_NORM_STD = np.array([0.229, 0.224, 0.225])
332 img_norm = (img / 255.0 - IMG_NORM_MEAN) / IMG_NORM_STD
333 img_norm = img_norm.transpose(2, 0, 1).astype(np.float32)
334 return img_norm, np.array(center), np.array(scale)
335
336
337class Pose2d:

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected