MCPcopy Create free account
hub / github.com/DeepLabCut/DeepLabCut / compute_metrics

Function compute_metrics

deeplabcut/core/metrics/api.py:20–136  ·  view source on GitHub ↗

Computes pose estimation performance metrics. Given ground truth pose labels and predictions on a dataset, computes RMSE and pose mAP/mAR using OKS. The image paths in the ground_truth dict must be the same as the ones in the predictions dict. Single animal RMSE is computed by

(
    ground_truth: dict[str, np.ndarray],
    predictions: dict[str, np.ndarray],
    single_animal: bool = False,
    unique_bodypart_gt: dict[str, np.ndarray] | None = None,
    unique_bodypart_poses: dict[str, np.ndarray] | None = None,
    pcutoff: float = -1,
    oks_bbox_margin: int = 0,
    oks_sigma: float | np.ndarray = 0.1,
    per_keypoint_rmse: bool = False,
    compute_detection_rmse: bool = True,
)

Source from the content-addressed store, hash-verified

18
19
20def compute_metrics(
21 ground_truth: dict[str, np.ndarray],
22 predictions: dict[str, np.ndarray],
23 single_animal: bool = False,
24 unique_bodypart_gt: dict[str, np.ndarray] | None = None,
25 unique_bodypart_poses: dict[str, np.ndarray] | None = None,
26 pcutoff: float = -1,
27 oks_bbox_margin: int = 0,
28 oks_sigma: float | np.ndarray = 0.1,
29 per_keypoint_rmse: bool = False,
30 compute_detection_rmse: bool = True,
31) -> dict:
32 """Computes pose estimation performance metrics.
33
34 Given ground truth pose labels and predictions on a dataset, computes RMSE and pose
35 mAP/mAR using OKS.
36
37 The image paths in the ground_truth dict must be the same as the ones in the
38 predictions dict.
39
40 Single animal RMSE is computed by simply calculating the Euclidean distance between
41 each ground truth keypoint and the corresponding prediction.
42
43 Multi-animal RMSE is computed differently: predictions are first matched to ground
44 truth individuals using greedy OKS matching. OKS (or object keypoint similarity) is
45 a similarity metric for keypoints (you can read more about it and its definition
46 here: https://cocodataset.org/#keypoints-eval). RMSE is then computed only between
47 predictions and the ground truth pose they are matched to, only when the OKS is
48 greater than a small threshold. Predictions that cannot be matched to any ground
49 truth with non-zero OKS are not used to compute RMSE.
50
51 Args:
52 ground_truth: The ground truth pose for which to compute metrics in the dataset.
53 This should be a dictionary mapping strings (image UIDs, such as image
54 paths) to ground truth pose for the image. The pose arrays should be
55 in the format (num_individuals, num_bodyparts, 3), where the 3 values are
56 x, y and visibility. The ``num_individuals`` corresponds to the number of
57 individuals labeled in each image.
58 predictions: The predicted poses for which to compute metrics in the dataset.
59 This should be a dictionary mapping strings (image UIDs, such as image
60 paths) to pose predictions for the image. The pose arrays should be
61 in the format (num_predictions, num_bodyparts, 3), where the 3 values are
62 x, y and score. The number of predictions can be different to the number of
63 ground truth individuals labeled for an image.
64 single_animal: Whether the metrics are being computed on a single-animal or
65 multi-animal dataset. This has an impact on RMSE computation.
66 unique_bodypart_gt: If unique bodyparts are defined for the dataset, they should
67 be contained in this dict in the same format as the ``ground_truth`` dict.
68 unique_bodypart_poses: If unique bodyparts are defined for the dataset, the
69 predictions should be contained in this dict in the same format as the
70 ``predictions`` dict.
71 pcutoff: The threshold to compute the "rmse_cutoff" score (RMSE of all
72 predictions with score above the cutoff).
73 oks_bbox_margin: The margin to add around keypoints to compute the area for OKS
74 computation.
75 oks_sigma: The OKS sigma to use to compute pose.
76 per_keypoint_rmse: Compute per-keypoint RMSE values.
77 compute_detection_rmse: Computes detection RMSE (without animal assembly) if the

Callers

nothing calls this directly

Calls 1

prepare_evaluation_dataFunction · 0.85

Tested by

no test coverage detected