pose_split
sleap.qc.features.pose_split
¶
Pose-split (chimera) features.
A chimera is a single labeled instance whose keypoints actually span two different animals: e.g. the head/thorax of animal A connected to the abdomen of animal B. This typically shows up as a skeleton that is internally consistent in two tight clusters joined by a single, abnormally stretched "bridging" edge.
This module provides a pure function :func:compute_pose_split that scores how
chimera-like a single pose is. It is deliberately argument-driven (points,
adjacency, learned edge-length stats) so it can be unit-tested in isolation and
so the detector's already-computed baseline statistics can be reused.
The primary signal is graph-based:
- On the subgraph induced by the visible nodes, find the connected bridging
edge whose normalized length z-score
z = (len - mean) / stdis largest. - Cut that edge. If the visible subgraph splits cleanly into two components,
measure how balanced the split is (
split_ratio = smaller / total). - Measure how far apart the two clusters sit relative to their own internal
spread (
gap_ratio). A real chimera has two compact clusters separated by a wide gap.
A high split_score requires all three (large bridging z, balanced split,
large gap). This gating is what keeps it from firing on a normal pose or on a
partially-occluded single animal (whose visible subgraph is merely disconnected
without an abnormally long bridging edge).
For skeletons where the graph signal is weak or unavailable (star skeletons,
very short skeletons, or missing adjacency), a skeleton-agnostic 2-means
bimodality :func:compute_pose_split_fallback is used instead.
Functions:
| Name | Description |
|---|---|
compute_pose_split |
Score how chimera-like a single pose is (one instance, two animals). |
compute_pose_split_fallback |
Skeleton-agnostic 2-means bimodality fallback. |
compute_pose_split(points, adjacency, edge_means, edge_stds, min_visible=MIN_VISIBLE_NODES)
¶
Score how chimera-like a single pose is (one instance, two animals).
Operates on the subgraph induced by the visible nodes:
- Bridging edge. Among visible edges with learned length stats, find
the one with the largest normalized stretch
z = (len - mean) / std. - Balanced split. Remove that edge; if the visible subgraph splits into
exactly two components,
split_ratio = smaller / totalmeasures balance (ideal ~0.3-0.5). - Gap.
gap_ratio = ||centroidA - centroidB|| / max(spread_A, spread_B)measures how far the clusters sit relative to their own internal spread.
The returned split_score is the gated product of these signals, so it
is only high when a long bridging edge separates two balanced, well-spaced
clusters. This is what prevents false positives on:
- a normal pose (no bridging edge with a large z; small gap_ratio),
- a partially occluded single animal (the visible subgraph may be disconnected, but there is no abnormally stretched bridging edge joining two balanced clusters), and
- two genuinely close, correctly-merged animals (small gap relative to spread).
If adjacency is unavailable, or the skeleton is too star-like / short for a
bridging edge to be meaningful, falls back to
:func:compute_pose_split_fallback (2-means bimodality).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
points
|
ndarray
|
(N_nodes, 2) coordinate array (NaN for invisible nodes). |
required |
adjacency
|
Optional[dict[int, list[int]]]
|
Maps node_index -> list of neighbor indices (skeleton
edges). Pass |
required |
edge_means
|
dict[tuple[int, int], float]
|
Maps sorted |
required |
edge_stds
|
dict[tuple[int, int], float]
|
Maps sorted |
required |
min_visible
|
int
|
Minimum visible nodes required to attempt a split. |
MIN_VISIBLE_NODES
|
Returns:
| Type | Description |
|---|---|
dict[str, float]
|
Dictionary with:
|
Source code in sleap/qc/features/pose_split.py
325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 | |
compute_pose_split_fallback(points, min_visible=MIN_VISIBLE_NODES)
¶
Skeleton-agnostic 2-means bimodality fallback.
Used for star/short skeletons or when adjacency is unavailable. Splits the visible nodes into two clusters with 2-means and reports a silhouette-like separation score. This intentionally ignores skeleton edges, so it cannot use a bridging-edge z-score; the gate therefore relies entirely on geometry (balanced split + wide gap).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
points
|
ndarray
|
(N_nodes, 2) coordinate array (NaN for invisible nodes). |
required |
min_visible
|
int
|
Minimum visible nodes required to attempt a split. |
MIN_VISIBLE_NODES
|
Returns:
| Type | Description |
|---|---|
dict[str, float]
|
Dictionary with keys |
Source code in sleap/qc/features/pose_split.py
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 | |