frame_level
sleap.qc.frame_level
¶
Frame-level quality checks: instance count, duplicate detection.
Classes:
| Name | Description |
|---|---|
InstanceCountChecker |
Detect frames with unusual instance counts (incomplete annotation). |
Functions:
| Name | Description |
|---|---|
check_negative_frame |
Check whether a negative frame inconsistently still has instances. |
compute_instance_iou |
Compute IOU between two instances based on bounding boxes. |
compute_node_overlap |
Compute node-wise overlap for partial duplicate detection. |
detect_duplicates |
Detect duplicate instances in a frame. |
InstanceCountChecker
¶
Detect frames with unusual instance counts (incomplete annotation).
Attributes:
| Name | Type | Description |
|---|---|---|
per_video |
Whether to compute expected counts per video. |
|
expected_counts |
dict[str, float]
|
Video-specific expected counts. |
global_expected |
float
|
Global expected count. |
Methods:
| Name | Description |
|---|---|
__init__ |
Initialize checker. |
check |
Check if a frame's instance count is unusual. |
fit |
Learn expected instance counts. |
Source code in sleap/qc/frame_level.py
__init__(per_video=True)
¶
Initialize checker.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
per_video
|
bool
|
If True, compute expected counts per video. |
True
|
Source code in sleap/qc/frame_level.py
check(instance_count, video_id=None)
¶
Check if a frame's instance count is unusual.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
instance_count
|
int
|
Number of instances in frame. |
required |
video_id
|
Optional[str]
|
Optional video ID for per-video comparison. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, object]
|
Dictionary with: - is_incomplete: True if fewer instances than expected - expected_count: expected count for this video - actual_count: actual count - count_difference: actual - expected |
Source code in sleap/qc/frame_level.py
fit(frame_counts, video_ids=None)
¶
Learn expected instance counts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frame_counts
|
list[int]
|
List of instance counts per frame. |
required |
video_ids
|
Optional[list[str]]
|
Optional list of video IDs per frame. |
None
|
Returns:
| Type | Description |
|---|---|
'InstanceCountChecker'
|
Self for chaining. |
Source code in sleap/qc/frame_level.py
check_negative_frame(is_negative, instance_count)
¶
Check whether a negative frame inconsistently still has instances.
A negative (background) frame is explicitly marked as containing no animals. If it still has instances, it is either a mislabel or instances were added through a path that did not clear the negative flag.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
is_negative
|
bool
|
Whether the frame is marked as a negative frame. |
required |
instance_count
|
int
|
Number of instances on the frame. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the frame is marked negative but still has instances. |
Source code in sleap/qc/frame_level.py
compute_instance_iou(points_a, points_b)
¶
Compute IOU between two instances based on bounding boxes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
points_a
|
ndarray
|
(N_nodes, 2) array for instance A (NaN for invisible). |
required |
points_b
|
ndarray
|
(N_nodes, 2) array for instance B. |
required |
Returns:
| Type | Description |
|---|---|
float
|
IOU value (0-1). |
Source code in sleap/qc/frame_level.py
compute_node_overlap(points_a, points_b, distance_threshold=10.0)
¶
Compute node-wise overlap for partial duplicate detection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
points_a
|
ndarray
|
(N_nodes, 2) array for instance A. |
required |
points_b
|
ndarray
|
(N_nodes, 2) array for instance B. |
required |
distance_threshold
|
float
|
Max distance to consider nodes as overlapping. |
10.0
|
Returns:
| Type | Description |
|---|---|
dict[str, object]
|
Dictionary with: - common_nodes: list of node indices visible in both - overlapping_nodes: list of nodes within threshold - mean_distance: mean distance at common nodes - overlap_ratio: overlapping_nodes / common_nodes |
Source code in sleap/qc/frame_level.py
detect_duplicates(instances, iou_threshold=0.5, node_distance_threshold=10.0, node_overlap_ratio=0.8)
¶
Detect duplicate instances in a frame.
Uses both IOU and node-wise overlap to catch partial duplicates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
instances
|
list[ndarray]
|
List of (N_nodes, 2) arrays. |
required |
iou_threshold
|
float
|
IOU above this = duplicate. |
0.5
|
node_distance_threshold
|
float
|
Distance for node overlap. |
10.0
|
node_overlap_ratio
|
float
|
Min overlap ratio to flag as duplicate. |
0.8
|
Returns:
| Type | Description |
|---|---|
list[dict]
|
List of duplicate pair dictionaries with: - index_a, index_b: instance indices - iou: IOU value - node_overlap: node overlap info - reason: "iou" or "node_overlap" |