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

Adding support for evaluating keypoints #2776

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
2 changes: 1 addition & 1 deletion fiftyone/core/patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import fiftyone.core.view as fov


_PATCHES_TYPES = (fol.Detections, fol.Polylines)
_PATCHES_TYPES = (fol.Detections, fol.Polylines, fol.Keypoints)
_NO_MATCH_ID = ""


Expand Down
2 changes: 1 addition & 1 deletion fiftyone/utils/eval/detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def evaluate_detections(
fov.validate_collection_label_fields(
samples,
(pred_field, gt_field),
(fol.Detections, fol.Polylines, fol.TemporalDetections),
(fol.Detections, fol.Polylines, fol.TemporalDetections, fol.Keypoints),
same_type=True,
)

Expand Down
30 changes: 30 additions & 0 deletions fiftyone/utils/iou.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import fiftyone.core.utils as fou
import fiftyone.core.validation as fov

from scipy.spatial import distance

from .utils3d import compute_cuboid_iou as _compute_cuboid_iou

sg = fou.lazy_import("shapely.geometry")
Expand Down Expand Up @@ -89,6 +91,12 @@ def compute_ious(
preds, gts, error_level, iscrowd=iscrowd, classwise=classwise
)


if isinstance(preds[0], fol.Keypoints):
return _compute_keypoint_similarity(
preds, gts, iscrowd=iscrowd, classwise=classwise
)

if use_masks:
# @todo when tolerance is None, consider using dense masks rather than
# polygonal approximations?
Expand Down Expand Up @@ -556,6 +564,28 @@ def _compute_polyline_ious(
return ious


def _compute_keypoint_similarity(preds, gts, error_level, iscrowd=None, classwise=False, gt_crowds=None):
#calculate euclidean distance of each keypoint
sim_score = np.zeros((len(preds), len(gts)))

for j, gt in enumerate(gts):
for i, pt in enumerate(preds):
gt_points=[]
pt_points=[]
for x in gt['points']:
gt_points.append(x)
for y in pt['points']:
pt_points.append(y)

gt_points=sum(gt_points, [])

pt_points=sum(pt_points, [])

sim_score[i, j] = 1/(1 + distance.euclidean(tuple(gt_points),tuple(pt_points)))

return sim_score


def _compute_mask_ious(
preds, gts, tolerance, error_level, iscrowd=None, classwise=False
):
Expand Down