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