sleap.nn.utils¶
This module contains generic utilities used for training and inference.
-
sleap.nn.utils.
compute_iou
(bbox1: numpy.ndarray, bbox2: numpy.ndarray) → float[source]¶ Computes the intersection over union for a pair of bounding boxes.
- Parameters
bbox1 – Bounding box specified by corner coordinates [y1, x1, y2, x2].
bbox2 – Bounding box specified by corner coordinates [y1, x1, y2, x2].
- Returns
A float scalar calculated as the ratio between the areas of the intersection and the union of the two bounding boxes.
-
sleap.nn.utils.
group_array
(X: numpy.ndarray, groups: numpy.ndarray, axis: int = 0) → Dict[numpy.ndarray, numpy.ndarray][source]¶ Groups an array into a dictionary keyed by a grouping vector.
- Parameters
X – Numpy array with length n along the specified axis.
groups – Vector of n values denoting the group that each slice of X should be assigned to. This is also referred to as an indicator, indexing, class, or labels vector.
axis – Dimension of X to group on. The length of this axis in X must correspond to the length of groups.
- Returns
A dictionary with keys mapping each unique value in groups to a subset of X.
References
See this blog post <https://jakevdp.github.io/blog/2017/03/22/group-by-from-scratch/> for performance comparisons of different approaches.
Example
>>> group_array(np.arange(5), np.array([1, 5, 2, 1, 5])) {1: array([0, 3]), 5: array([1, 4]), 2: array([2])}