sleap.info.metrics

Module for producing prediction metrics for SLEAP datasets.

sleap.info.metrics.calculate_pairwise_cost(instances_a: List[sleap.instance.Instance], instances_b: List[sleap.instance.Instance], cost_function: Callable)numpy.ndarray[source]

Calculate (a * b) matrix of pairwise costs using cost function.

sleap.info.metrics.compare_instance_lists(instances_a: List[sleap.instance.Instance], instances_b: List[sleap.instance.Instance])numpy.ndarray[source]

Given two lists of corresponding Instances, returns (instances * nodes) matrix of distances between corresponding nodes.

sleap.info.metrics.list_points_array(instances: List[sleap.instance.Instance])numpy.ndarray[source]

Given list of Instances, returns (instances * nodes * 2) matrix.

sleap.info.metrics.match_instance_lists(instances_a: List[sleap.instance.Instance], instances_b: List[sleap.instance.Instance], cost_function: Callable)Tuple[List[sleap.instance.Instance], List[sleap.instance.Instance]][source]

Sorts two lists of Instances to find best overall correspondence for a given cost function (e.g., total distance between points).

sleap.info.metrics.match_instance_lists_nodewise(instances_a: List[sleap.instance.Instance], instances_b: List[sleap.instance.Instance], thresh: float = 5)Tuple[List[sleap.instance.Instance], List[sleap.instance.Instance]][source]

For each node for each instance in the first list, pairs it with the closest corresponding node from any instance in the second list.

sleap.info.metrics.matched_instance_distances(labels_gt: sleap.io.dataset.Labels, labels_pr: sleap.io.dataset.Labels, match_lists_function: Callable, frame_range: Optional[range] = None)Tuple[List[int], numpy.ndarray, numpy.ndarray, numpy.ndarray][source]

Distances between ground truth and predicted nodes over a set of frames.

Parameters
  • labels_gt – the Labels object with ground truth data

  • labels_pr – the Labels object with predicted data

  • match_lists_function – function for determining corresponding instances Takes two lists of instances and returns “sorted” lists.

  • frame_range (optional) – range of frames for which to compare data If None, we compare every frame in labels_gt with corresponding frame in labels_pr.

Returns

  • frame indices map: instance idx (for other matrices) -> frame idx

  • distance matrix: (instances * nodes)

  • ground truth points matrix: (instances * nodes * 2)

  • predicted points matrix: (instances * nodes * 2)

Return type

Tuple

sleap.info.metrics.nodeless_point_dist(inst_a: sleap.instance.Instance, inst_b: sleap.instance.Instance)numpy.ndarray[source]

Given two instances, returns array of distances for closest points ignoring node identities.

sleap.info.metrics.point_dist(inst_a: sleap.instance.Instance, inst_b: sleap.instance.Instance)numpy.ndarray[source]

Given two instances, returns array of distances for corresponding nodes.

sleap.info.metrics.point_match_count(dist_array: numpy.ndarray, thresh: float = 5)int[source]

Given an array of distances, returns number which are <= threshold.

sleap.info.metrics.point_nonmatch_count(dist_array: numpy.ndarray, thresh: float = 5)int[source]

Given an array of distances, returns number which are not <= threshold.