deeplabcut.core.metrics.distance_metrics
Implementations of methods to compute distance metrics such as RMSE or OKS.
Functions:
| Name | Description |
|---|---|
collect_pixel_errors |
Collects pixel errors for RMSE computation. |
compute_detection_rmse |
Computes the detection RMSE for pose predictions. |
compute_oks |
Computes the OKS for pose at different thresholds. |
compute_oks_matrix |
Computes the OKS score for each (prediction, gt) pair in an image. |
compute_rmse |
Computes the RMSE for pose predictions. |
match_predictions_for_rmse |
Matches GT keypoints to predictions to compute RMSE. |
collect_pixel_errors
collect_pixel_errors(pixel_errors: ndarray, keypoint_scores: ndarray, pcutoff: float) -> tuple[float, int, float, int]
Collects pixel errors for RMSE computation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
ndarray
|
The pixel errors to collect, of shape (num_matches, num_bodyparts) |
required |
|
ndarray
|
The scores corresponding to the pixel errors, of shape (num_matches, num_bodyparts). |
required |
|
float
|
The pcutoff to use when computing cutoff RMSE. |
required |
error, support, cutoff_error, support_cutoff
| Name | Type | Description |
|---|---|---|
error |
tuple[float, int, float, int]
|
The sum of all pixel errors. support: The number of valid pixel errors. cutoff_error: The sum of all pixel errors with score > pcutoff. support_cutoff: The number of valid pixel errors with score > pcutoff. |
Source code in deeplabcut/core/metrics/distance_metrics.py
compute_detection_rmse
compute_detection_rmse(
data: list[tuple[ndarray, ndarray]],
pcutoff: float | list[float],
data_unique: list[tuple[ndarray, ndarray]] | None = None,
) -> tuple[float, float]
Computes the detection RMSE for pose predictions.
The detection RMSE score does not take individual assemblies into account. It only judges the performance of the detections, matching each predicted keypoint to the closest ground truth for each bodypart.
This is the same way multi-animal RMSE was computed in DeepLabCut 2.X.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
list[tuple[ndarray, ndarray]]
|
The data for which to compute RMSE. This is a list containing (gt_poses, predicted_poses), where gt_pose is an array of shape (num_gt_individuals, num_bpts, 3) and predicted_poses is an array of shape (num_predictions, num_bpts, 3). For the GT, the 3 coordinates are (x, y, visibility) while for the pose they are (x, y, confidence score). |
required |
|
float | list[float]
|
The p-cutoff to use to compute RMSE. If a list, the cutoff for each bodypart is set individually. The list must have length num_bodyparts + num_unique_bodyparts. |
required |
|
list[tuple[ndarray, ndarray]] | None
|
Unique bodypart ground truth and predictions to include in RMSE computations, if there are any such bodyparts. |
None
|
Returns:
| Type | Description |
|---|---|
tuple[float, float]
|
The detection RMSE and detection RMSE after removing all detections with a score below the pcutoff. |
Source code in deeplabcut/core/metrics/distance_metrics.py
329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 | |
compute_oks
compute_oks(
data: list[tuple[ndarray, ndarray]],
oks_bbox_margin: float = 0.0,
oks_sigma: float | ndarray = 0.1,
oks_thresholds: ndarray | None = None,
oks_recall_thresholds: ndarray | None = None,
) -> dict[str, float]
Computes the OKS for pose at different thresholds.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
list[tuple[ndarray, ndarray]]
|
The data for which to compute OKS mAP: a list containing (gt_poses, predicted_poses) tuples, where gt_pose is an array of shape (num_gt_individuals, num_bpts, 3) and predicted_poses is an array of shape (num_predictions, num_bpts, 3). For the GT, the 3 coordinates are (x, y, visibility) while for the pose they are (x, y, confidence score). |
required |
|
float | ndarray
|
The OKS sigma to use to compute pose. |
0.1
|
|
float
|
The margin to add around keypoints to compute the area for OKS computation. |
0.0
|
|
ndarray | None
|
The OKS thresholds at which to compute AP. If None, defaults to (0.5, 0.55, 0.6, ..., 0.9, 0.95). |
None
|
|
ndarray | None
|
The recall thresholds to use to compute mAP. If None, defaults to the same default values used in pycocotools. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, float]
|
A dictionary containing mAP and mAR scores. |
Source code in deeplabcut/core/metrics/distance_metrics.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | |
compute_oks_matrix
compute_oks_matrix(
ground_truth: ndarray, predictions: ndarray, oks_sigma: float | ndarray, oks_bbox_margin: float = 0.0
) -> np.ndarray
Computes the OKS score for each (prediction, gt) pair in an image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
ndarray
|
The GT poses for an image, shape (n_individuals, n_kpts, 2) |
required |
|
ndarray
|
The predicted poses in the image, shape (n_pred, n_kpts, 2) |
required |
|
float | ndarray
|
The sigma value to use to compute OKS |
required |
|
float
|
The margin to add around keypoints when computing the area. FIXME(niels) We should allow the use of ground truth bboxes to get area |
0.0
|
Returns:
| Type | Description |
|---|---|
ndarray
|
A matrix of shape (n_pred, n_kpts) where entry (i, j) is the OKS between prediction i and ground truth j. |
Source code in deeplabcut/core/metrics/distance_metrics.py
compute_rmse
compute_rmse(
data: list[tuple[ndarray, ndarray]],
single_animal: bool,
pcutoff: float | list[float],
data_unique: list[tuple[ndarray, ndarray]] | None = None,
per_keypoint_results: bool = False,
oks_bbox_margin: float = 0.0,
) -> dict[str, float]
Computes the RMSE for pose predictions.
Single animal RMSE is computed by simply calculating the distance between each ground truth keypoint and the corresponding prediction.
Multi-animal RMSE is computed differently: predictions are first matched to ground truth individuals using greedy OKS matching. RMSE is then computed only between predictions and the ground truth pose they are matched to, only when the OKS is non-zero (greater than a small threshold). Predictions that cannot be matched to any ground truth with non-zero OKS are not used to compute RMSE.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
list[tuple[ndarray, ndarray]]
|
The data for which to compute RMSE. This is a list containing (gt_poses, predicted_poses), where gt_pose is an array of shape (num_gt_individuals, num_bpts, 3) and predicted_poses is an array of shape (num_predictions, num_bpts, 3). For the GT, the 3 coordinates are (x, y, visibility) while for the pose they are (x, y, confidence score). |
required |
|
bool
|
Whether this is a single animal dataset. |
required |
|
float | list[float]
|
The p-cutoff to use to compute RMSE. If a list, the cutoff for each bodypart is set individually. The list must have length num_bodyparts + num_unique_bodyparts. |
required |
|
list[tuple[ndarray, ndarray]] | None
|
Unique bodypart ground truth and predictions to include in RMSE computations, if there are any such bodyparts. |
None
|
|
bool
|
Whether to compute the RMSE for each individual keypoint. |
False
|
|
float
|
When single_animal is False, predictions are matched to GT using OKS. This is the margin used to apply when computing the bbox from the pose to compute OKS. |
0.0
|
Returns:
| Type | Description |
|---|---|
dict[str, float]
|
A dictionary matching metric names to values. It will at least have "rmse" and
"rmse_cutoff" keys. If |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in deeplabcut/core/metrics/distance_metrics.py
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 | |
match_predictions_for_rmse
match_predictions_for_rmse(
data: list[tuple[ndarray, ndarray]], single_animal: bool, oks_bbox_margin: float = 0.0
) -> list[matching.PotentialMatch]
Matches GT keypoints to predictions to compute RMSE.
Single animal RMSE is computed by simply calculating the distance between each ground truth keypoint and the corresponding prediction.
Multi-animal RMSE is computed differently: predictions are first matched to ground truth individuals using greedy OKS matching. RMSE is then computed only between predictions and the ground truth pose they are matched to, only when the OKS is non-zero (greater than a small threshold). Predictions that cannot be matched to any ground truth with non-zero OKS are not used to compute RMSE.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
list[tuple[ndarray, ndarray]]
|
The data for which to compute RMSE. This is a list containing (gt_poses, predicted_poses), where gt_pose is an array of shape (num_gt_individuals, num_bpts, 3) and predicted_poses is an array of shape (num_predictions, num_bpts, 3). For the GT, the 3 coordinates are (x, y, visibility) while for the pose they are (x, y, confidence score). |
required |
|
bool
|
Whether this is a single animal dataset. |
required |
|
float
|
When single_animal is False, predictions are matched to GT using OKS. This is the margin used to apply when computing the bbox from the pose to compute OKS. |
0.0
|
Returns:
| Type | Description |
|---|---|
list[PotentialMatch]
|
A list containing the predictions matched to ground truth. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |