detections
sleap_nn.tracking.mot.detections
¶
Per-frame detection arrays for the MOT trackers.
:func:extract_detections turns one frame's sleap-io detections (pose
Instance / PredictedInstance or PredictedSegmentationMask) into the
vectorized :class:FrameDetections every tracker, the calibration and the
identity linker operate on. The source objects are kept (sources) so tracks
can be written back onto them.
Geometry conventions (shared by every consumer -- never mix them):
raw_boxesis the tight extent of the visible keypoints (or the mask's bounding box),xyxyin image pixels.boxesisraw_boxespadded bybox_padding * max(w, h)on each side.centroidsis the CENTER OFraw_boxes-- the same reference point the Kalman filters track (box center). Do not use the node median here: mixing the two reference points injects a fake per-frame displacement.
Classes:
| Name | Description |
|---|---|
FrameDetections |
Vectorized detections of one frame. |
Functions:
| Name | Description |
|---|---|
extract_detections |
Build :class: |
has_usable_embedding |
Whether |
normalize_scores |
Divide |
widen_boxes |
Floor |
FrameDetections
¶
Vectorized detections of one frame.
Attributes:
| Name | Type | Description |
|---|---|---|
frame_idx |
int
|
Frame index of the detections. |
sources |
list
|
The original sleap-io objects, in input order. |
boxes |
ndarray
|
|
raw_boxes |
ndarray
|
|
centroids |
ndarray
|
|
keypoints |
Optional[ndarray]
|
|
scores |
ndarray
|
|
embeddings |
Optional[ndarray]
|
|
has_embedding |
ndarray
|
|
valid |
ndarray
|
|
n_visible |
ndarray
|
|
n_nodes |
int
|
Nodes per detection |
Methods:
| Name | Description |
|---|---|
__len__ |
Number of detections. |
empty |
Return an empty frame (zero detections) with correctly shaped arrays. |
subset |
Return the detections at |
Source code in sleap_nn/tracking/mot/detections.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 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 | |
__len__()
¶
empty(frame_idx, n_nodes=1)
classmethod
¶
Return an empty frame (zero detections) with correctly shaped arrays.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frame_idx
|
int
|
Frame index. |
required |
n_nodes
|
int
|
Nodes per detection; sets the |
1
|
Returns:
| Name | Type | Description |
|---|---|---|
A |
FrameDetections
|
class: |
Source code in sleap_nn/tracking/mot/detections.py
subset(idx)
¶
Return the detections at idx (index array or bool mask), copied.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
idx
|
ndarray
|
Integer indices (any order) or a boolean mask of length
|
required |
Returns:
| Type | Description |
|---|---|
FrameDetections
|
A new :class: |
Raises:
| Type | Description |
|---|---|
ValueError
|
If a boolean mask has the wrong length. |
Source code in sleap_nn/tracking/mot/detections.py
extract_detections(objs, frame_idx, *, carrier='pose', box_padding=0.1, pseudo_box_size=None, score_mode='auto', embedding_dim=None, min_box_size=None)
¶
Build :class:FrameDetections from one frame's sleap-io detections.
Geometry: a pose's raw box is the extent of its visible (finite) nodes; a
mask's is mask.bbox (image space), and an empty mask is invalid. Each
object is dispatched with
:func:~sleap_nn.tracking.utils.is_segmentation_mask. A valid detection is
DEGENERATE when it is a pose with a single visible node or its raw box is
narrower than 1 px on either axis: its raw and padded boxes then both become
the square of side pseudo_box_size centered on its centroid (with
pseudo_box_size=None, the raw box is instead floored at 1 px per axis
around its center and padded as usual). Centroids are raw-box centers.
Scores (score_mode), then non-finite -> 1.0 and clipped to [0, 1]:
"auto": predicted pose -> mean point score over its visible nodes (obj.scoreif none is finite); predicted mask ->obj.score; userInstance/ user mask (noscore) -> 1.0."instance":obj.score(1.0 if absent)."none": 1.0 everywhere.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
objs
|
Sequence
|
The frame's detections: pose instances ( |
required |
frame_idx
|
int
|
Frame index of the detections. |
required |
carrier
|
str
|
|
'pose'
|
box_padding
|
float
|
Fraction of |
0.1
|
pseudo_box_size
|
Optional[float]
|
Side (px) of the square box used for degenerate
geometry (a single visible node, or a raw box narrower than 1 px).
|
None
|
score_mode
|
str
|
|
'auto'
|
embedding_dim
|
Optional[int]
|
Expected appearance-vector dimension; vectors of another
dimension are treated as missing. |
None
|
min_box_size
|
Optional[float]
|
Minimum side (px) of the PADDED box on each axis; narrower
boxes are widened symmetrically around their center. Keeps IoU
meaningful for thin poses (nodes nearly collinear along one axis).
Raw boxes (the OKS scale) are not changed. |
None
|
Returns:
| Type | Description |
|---|---|
FrameDetections
|
The frame's :class: |
Raises:
| Type | Description |
|---|---|
ValueError
|
On an unknown |
Source code in sleap_nn/tracking/mot/detections.py
315 316 317 318 319 320 321 322 323 324 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 471 | |
has_usable_embedding(obj)
¶
Whether obj carries a usable appearance vector (see :func:_usable_vector).
A frame-level check can additionally drop a usable vector whose dimension
differs from the frame's (:func:extract_detections); per detection, only
presence, finiteness and a non-zero norm can be judged.
Source code in sleap_nn/tracking/mot/detections.py
normalize_scores(dets, normalizer)
¶
Divide dets.scores by normalizer and clip to [0, 1], in place.
The per-video score normalization of MOTParams.normalize_scores (the
normalizer is :func:~sleap_nn.tracking.mot.calibration.score_normalizer:
the video's score q95). Apply it exactly once per extraction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dets
|
FrameDetections
|
Detections to modify. |
required |
normalizer
|
Optional[float]
|
Positive divisor; |
required |
Source code in sleap_nn/tracking/mot/detections.py
widen_boxes(dets, min_box_size)
¶
Floor dets.boxes (padded) at min_box_size per axis, in place.
Same rule as extract_detections(min_box_size=...), for detections that
were already extracted. Raw boxes are not changed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dets
|
FrameDetections
|
Detections to modify. |
required |
min_box_size
|
Optional[float]
|
Minimum padded side (px); |
required |