Calculate the normalized distances between preds and target. Note: batch_size: N num_keypoints: K dimension of keypoints: D (normally, D=2 or D=3) Args: preds (np.ndarray[N, K, D]): Predicted keypoint location. targets (np.ndarray[N, K, D]): Groundtr
(preds, targets, mask, normalize)
| 354 | |
| 355 | |
| 356 | def _calc_distances(preds, targets, mask, normalize): |
| 357 | """Calculate the normalized distances between preds and target. |
| 358 | |
| 359 | Note: |
| 360 | batch_size: N |
| 361 | num_keypoints: K |
| 362 | dimension of keypoints: D (normally, D=2 or D=3) |
| 363 | |
| 364 | Args: |
| 365 | preds (np.ndarray[N, K, D]): Predicted keypoint location. |
| 366 | targets (np.ndarray[N, K, D]): Groundtruth keypoint location. |
| 367 | mask (np.ndarray[N, K]): Visibility of the target. False for invisible |
| 368 | joints, and True for visible. Invisible joints will be ignored for |
| 369 | accuracy calculation. |
| 370 | normalize (np.ndarray[N, D]): Typical value is heatmap_size |
| 371 | |
| 372 | Returns: |
| 373 | np.ndarray[K, N]: The normalized distances. |
| 374 | If target keypoints are missing, the distance is -1. |
| 375 | """ |
| 376 | N, K, _ = preds.shape |
| 377 | distances = np.full((N, K), -1, dtype=np.float32) |
| 378 | # handle invalid values |
| 379 | normalize[np.where(normalize <= 0)] = 1e6 |
| 380 | distances[mask] = np.linalg.norm( |
| 381 | ((preds - targets) / normalize[:, None, :])[mask], axis=-1) |
| 382 | return distances.T |
| 383 | |
| 384 | |
| 385 | def _distance_acc(distances, thr=0.5): |
no outgoing calls
no test coverage detected