duplicate_split
sleap.qc.features.duplicate_split
¶
Split/duplicate instance features for frame-level QC.
This module provides pure helpers used by sleap.qc.frame_level to
strengthen duplicate-instance detection. The existing IoU and co-visible
node-overlap signals catch near-identical overlapping copies (one animal
labeled twice on the same nodes), but they miss the complementary
split case: a single animal split across two instances that each label a
largely disjoint set of nodes (e.g. instance A labels head/front, instance
B labels tail/back). Together the two "halves" form one coherent animal.
The functions here are deliberately scale-normalized (by the median edge length learned from the dataset, or the bounding-box diagonal of the larger instance as a fallback) so a single threshold works across recordings, and they NaN-guard every coordinate so absent/invisible nodes never leak into a score.
Functions:
| Name | Description |
|---|---|
compute_split_duplicate |
Score whether two instances are one animal split across both. |
duplicate_score |
Combine duplicate signals into one graded confidence in |
compute_split_duplicate(points_a, points_b, edge_means=None)
¶
Score whether two instances are one animal split across both.
Detects the complementary split failure mode that bbox-IoU and co-visible node overlap miss: the two instances are visible on largely disjoint node sets (few co-visible nodes), yet together their union pose forms a single coherent animal -- the two "halves" are spatially contiguous (small inter-instance nearest-node distance relative to scale) and the union's extent matches a single animal rather than two side by side.
The score is the product of three graded, scale-normalized signals:
- Disjointness -- the two visible-node sets must be largely complementary (this is the precondition that distinguishes a split from an identical overlapping copy, which shares nodes).
- Proximity -- the nearest node of A must be close to the nearest node of B (the halves meet at the body). This is the key signal that keeps the detector from firing on two genuinely distinct animals labeled on disjoint nodes, which leave a clear gap between them.
- Coherence -- the inter-instance gap must be small relative to the instances' own internal node spacing, i.e. the two halves join like a normal skeleton edge ("nested") rather than sitting several body-widths apart as two animals side by side would.
Distances are normalized by the median edge length from edge_means (or
the larger instance's bbox diagonal as a fallback), so the result is
translation-, rotation-, and scale-invariant and thresholdable with a
single cutoff.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
points_a
|
ndarray
|
|
required |
points_b
|
ndarray
|
|
required |
edge_means
|
Optional[dict]
|
Optional mapping of edge |
None
|
Returns:
| Type | Description |
|---|---|
dict
|
Dictionary with:
|
Source code in sleap/qc/features/duplicate_split.py
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 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 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 | |
duplicate_score(iou, node_overlap_ratio, split_duplicate_score)
¶
Combine duplicate signals into one graded confidence in [0, 1].
Merges the three complementary duplicate signals so a caller can apply a single threshold and get a graded confidence instead of three booleans:
iou-- bbox intersection-over-union (overlapping copies).node_overlap_ratio-- fraction of co-visible nodes that coincide (partial overlapping copies, even at low IoU).split_duplicate_score-- the complementary split signal from :func:compute_split_duplicate(one animal split on disjoint nodes).
A saturating max is used: any one signal firing strongly is enough to
flag a duplicate, and the score never exceeds 1. Inputs are individually
clamped to [0, 1] and NaN inputs are treated as 0 so a missing
signal cannot inflate or corrupt the result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
iou
|
float
|
Bounding-box IoU between the two instances. |
required |
node_overlap_ratio
|
float
|
Co-visible node overlap ratio. |
required |
split_duplicate_score
|
float
|
Split-duplicate score. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Combined duplicate confidence in |