size
sleap.gui.learning.size
¶
Instance size computation and data structures for bounding boxes.
This module provides utilities for analyzing the distribution of instance sizes across a dataset, including rotation augmentation effects. Useful for: - Determining optimal crop sizes for centered-instance models - Identifying outlier instances that may be annotation errors
Classes:
| Name | Description |
|---|---|
InstanceSizeInfo |
Data class holding size info for a single instance. |
Functions:
| Name | Description |
|---|---|
compute_instance_sizes |
Compute sizes for all instances in labels. |
InstanceSizeInfo
dataclass
¶
Data class holding size info for a single instance.
Attributes:
| Name | Type | Description |
|---|---|---|
video_idx |
int
|
Index of the video in labels.videos. |
frame_idx |
int
|
Frame index within the video. |
instance_idx |
int
|
Index of the instance within the labeled frame. |
raw_width |
float
|
Bounding box width before rotation. |
raw_height |
float
|
Bounding box height before rotation. |
raw_size |
float
|
Maximum of width and height (square bounding box size). |
Methods:
| Name | Description |
|---|---|
get_rotated_size |
Calculate size needed for rotation augmentation range ±max_angle. |
Source code in sleap/gui/learning/size.py
get_rotated_size(max_angle_degrees)
¶
Calculate size needed for rotation augmentation range ±max_angle.
When rotation augmentation samples uniformly from [-max_angle, +max_angle], we need a size large enough to contain the instance at ANY angle in that range.
For a rectangle of size (w, h), rotated by angle theta: new_width = w*|cos(theta)| + h*|sin(theta)| new_height = w*|sin(theta)| + h*|cos(theta)|
The worst case (largest size needed) depends on the aspect ratio: - For most shapes (aspect ratio > 0.41), worst case is at 45 degrees - For very elongated shapes, worst case may be at 0 or 90 degrees
For ±180 (full rotation), we check 45 as the typical worst case. For ±theta where theta < 45, we check theta as the boundary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_angle_degrees
|
float
|
Maximum rotation angle in degrees. The augmentation range is assumed to be [-max_angle, +max_angle]. |
required |
Returns:
| Type | Description |
|---|---|
float
|
The size needed to contain the instance at any rotation within the specified range. |
Source code in sleap/gui/learning/size.py
compute_instance_sizes(labels, user_instances_only=True)
¶
Compute sizes for all instances in labels.
Iterates through all labeled frames and computes the bounding box dimensions for each instance. By default, only user-labeled instances are included (not predicted instances).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
labels
|
'sio.Labels'
|
A sleap_io.Labels object containing labeled frames. |
required |
user_instances_only
|
bool
|
If True (default), only include user-labeled instances, not predicted instances. |
True
|
Returns:
| Type | Description |
|---|---|
List[InstanceSizeInfo]
|
List of InstanceSizeInfo for each non-empty instance. |