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 / min_distance / max_distance: distance stats at common
nodes (all |
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, edge_means=None, duplicate_score_threshold=0.5)
¶
Detect duplicate instances in a frame.
Uses three complementary signals: bbox IOU and node-wise overlap (both catch
overlapping copies), plus the complementary split-duplicate signal (one
animal split across two instances labeled on largely disjoint nodes). The
three are combined by :func:~sleap.qc.features.duplicate_split.duplicate_score
into a single graded confidence.
A pair is flagged when the combined dscore >= duplicate_score_threshold
OR the existing IOU / node-overlap criteria fire, so this remains additive
and never drops a pair the previous logic would have flagged.
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
|
edge_means
|
Optional[dict]
|
Optional learned mean edge lengths (sorted |
None
|
duplicate_score_threshold
|
float
|
Combined-score cutoff at/above which a pair is flagged as a duplicate. |
0.5
|
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 - split_duplicate_score: complementary-split signal (0-1) - duplicate_score: combined graded confidence (0-1) - reason: "iou", "node_overlap", or "split_duplicate" |
Source code in sleap/qc/frame_level.py
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 | |