Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix confidence handling for keypoint evaluation #5344

Merged
merged 1 commit into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions fiftyone/utils/eval/coco.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import eta.core.utils as etau

import fiftyone.core.labels as fol
import fiftyone.core.plots as fop
import fiftyone.utils.iou as foui

Expand Down Expand Up @@ -552,14 +553,19 @@ def _coco_evaluation_setup(
label = obj.label if classwise else "all"
cats[label]["preds"].append(obj)

if isinstance(preds, fol.Keypoints):
sort_key = lambda p: np.nanmean(p.confidence) if p.confidence else -1
else:
sort_key = lambda p: p.confidence or -1

# Compute IoUs within each category
pred_ious = {}
for objects in cats.values():
gts = objects["gts"]
preds = objects["preds"]

# Highest confidence predictions first
preds = sorted(preds, key=lambda p: p.confidence or -1, reverse=True)
preds = sorted(preds, key=sort_key, reverse=True)

if max_preds is not None:
preds = preds[:max_preds]
Expand Down Expand Up @@ -587,6 +593,13 @@ def _compute_matches(

# Match each prediction to the highest available IoU ground truth
for pred in objects["preds"]:
if isinstance(pred, fol.Keypoint):
pred_conf = (
np.nanmean(pred.confidence) if pred.confidence else None
)
else:
pred_conf = pred.confidence

if pred.id in pred_ious:
best_match = None
best_match_iou = iou_thresh
Expand Down Expand Up @@ -638,7 +651,7 @@ def _compute_matches(
gt.label,
pred.label,
best_match_iou,
pred.confidence,
pred_conf,
gt.id,
pred.id,
iscrowd(gt),
Expand All @@ -651,7 +664,7 @@ def _compute_matches(
None,
pred.label,
None,
pred.confidence,
pred_conf,
None,
pred.id,
None,
Expand All @@ -665,7 +678,7 @@ def _compute_matches(
None,
pred.label,
None,
pred.confidence,
pred_conf,
None,
pred.id,
None,
Expand Down
21 changes: 17 additions & 4 deletions fiftyone/utils/eval/openimages.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import numpy as np

import fiftyone.core.labels as fol
import fiftyone.core.plots as fop
import fiftyone.utils.iou as foui

Expand Down Expand Up @@ -545,14 +546,19 @@ def _open_images_evaluation_setup(
if config.expand_pred_hierarchy and label != "all":
_expand_detection_hierarchy(cats, obj, config, "preds")

if isinstance(preds, fol.Keypoints):
sort_key = lambda p: np.nanmean(p.confidence) if p.confidence else -1
else:
sort_key = lambda p: p.confidence or -1

# Compute IoUs within each category
pred_ious = {}
for objects in cats.values():
gts = objects["gts"]
preds = objects["preds"]

# Highest confidence predictions first
preds = sorted(preds, key=lambda p: p.confidence or -1, reverse=True)
preds = sorted(preds, key=sort_key, reverse=True)

if max_preds is not None:
preds = preds[:max_preds]
Expand Down Expand Up @@ -583,6 +589,13 @@ def _compute_matches(

# Match each prediction to the highest available IoU ground truth
for pred in objects["preds"]:
if isinstance(pred, fol.Keypoint):
pred_conf = (
np.nanmean(pred.confidence) if pred.confidence else None
)
else:
pred_conf = pred.confidence

if pred.id in pred_ious:
best_match = None
best_match_iou = iou_thresh
Expand Down Expand Up @@ -667,7 +680,7 @@ def _compute_matches(
gt.label,
pred.label,
best_match_iou,
pred.confidence,
pred_conf,
gt.id,
pred.id,
)
Expand All @@ -679,15 +692,15 @@ def _compute_matches(
None,
pred.label,
None,
pred.confidence,
pred_conf,
None,
pred.id,
)
)
elif pred.label == cat:
pred[eval_key] = "fp"
matches.append(
(None, pred.label, None, pred.confidence, None, pred.id)
(None, pred.label, None, pred_conf, None, pred.id)
)

# Leftover GTs are false negatives
Expand Down
Loading