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

Function keypoint_pck_accuracy

tools/preprocess/pose2d_utils.py:488–524  ·  view source on GitHub ↗

Calculate the pose accuracy of PCK for each individual keypoint and the averaged accuracy across all keypoints for coordinates. Note: PCK metric measures accuracy of the localization of the body joints. The distances between predicted positions and the ground-truth ones

(pred, gt, mask, thr, normalize)

Source from the content-addressed store, hash-verified

486
487
488def keypoint_pck_accuracy(pred, gt, mask, thr, normalize):
489 """Calculate the pose accuracy of PCK for each individual keypoint and the
490 averaged accuracy across all keypoints for coordinates.
491
492 Note:
493 PCK metric measures accuracy of the localization of the body joints.
494 The distances between predicted positions and the ground-truth ones
495 are typically normalized by the bounding box size.
496 The threshold (thr) of the normalized distance is commonly set
497 as 0.05, 0.1 or 0.2 etc.
498
499 - batch_size: N
500 - num_keypoints: K
501
502 Args:
503 pred (np.ndarray[N, K, 2]): Predicted keypoint location.
504 gt (np.ndarray[N, K, 2]): Groundtruth keypoint location.
505 mask (np.ndarray[N, K]): Visibility of the target. False for invisible
506 joints, and True for visible. Invisible joints will be ignored for
507 accuracy calculation.
508 thr (float): Threshold of PCK calculation.
509 normalize (np.ndarray[N, 2]): Normalization factor for H&W.
510
511 Returns:
512 tuple: A tuple containing keypoint accuracy.
513
514 - acc (np.ndarray[K]): Accuracy of each keypoint.
515 - avg_acc (float): Averaged accuracy across all keypoints.
516 - cnt (int): Number of valid keypoints.
517 """
518 distances = _calc_distances(pred, gt, mask, normalize)
519
520 acc = np.array([_distance_acc(d, thr) for d in distances])
521 valid_acc = acc[acc >= 0]
522 cnt = len(valid_acc)
523 avg_acc = valid_acc.mean() if cnt > 0 else 0
524 return acc, avg_acc, cnt
525
526
527def keypoint_auc(pred, gt, mask, normalize, num_step=20):

Callers 2

pose_pck_accuracyFunction · 0.85
keypoint_aucFunction · 0.85

Calls 2

_calc_distancesFunction · 0.85
_distance_accFunction · 0.85

Tested by

no test coverage detected