splitting
sleap_nn.data.splitting
¶
Group-aware train/val splitter, decided before training.
For the embedding (crop -> vector re-ID) model type, the train/val partition is the
generalization axis: the model must only ever see the training partition, with val/test
held out by a group key so there is no leakage of the held-out group into training.
Three group keys are supported (mirroring the standalone reference
scratch/.../embedding/splits.py):
frame: stratified-random overLabeledFrameunits (frames mixed, identity-balanced via :class:~sklearn.model_selection.StratifiedGroupKFoldgrouped by frame). Both train and val contain all identities -- the in-distribution headline.video: hold out whole videos (by sio video index) via :class:~sklearn.model_selection.GroupKFold-- the honest cross-session number.identity: hold out whole track names (true open-vocab) via :class:~sklearn.model_selection.GroupKFoldgrouped by identity. Train and val identity sets are disjoint (degenerate for few identities; supported for completeness / verification-only).
The splitter operates at the LabeledFrame / detection level and returns new
sio.Labels objects containing the selected detections, so it composes directly with the
existing dataset builders (which iterate sio.Labels -> detections). For frame/video
each source frame stays whole on one side; for identity a source frame's detections are
filtered by identity, so a frame may contribute (disjoint) detections to both sides.
Both carriers are split. A detection is a pose instance (lf.instances) or a mask
(lf.masks); a mask LINKED to one of its frame's instances (mask.instance, as a
top-down segmentation or SAM output has) is not a detection of its own: it goes wherever
its instance goes, link intact. Keeping only one carrier per frame used to drop every mask
of a pose + mask frame, which silently flipped an embedding model from mask to pose
mode. Mask-only labels (e.g. the gerbil instance-segmentation data) carry all their
detections on lf.masks.
Functions:
| Name | Description |
|---|---|
split_labels_list_train_val |
Apply :func: |
split_labels_train_val |
Partition a single |
split_labels_list_train_val(labels_list, split_config)
¶
Apply :func:split_labels_train_val to each sio.Labels in a list.
Splits each input sio.Labels independently (video indices and track names are scoped
per file) and returns (train_labels_list, val_labels_list) aligned to the input list,
so the result drops straight into ModelTrainer.train_labels / .val_labels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
labels_list
|
List[Labels]
|
List of source |
required |
split_config
|
A |
required |
Returns:
| Type | Description |
|---|---|
Tuple[List[Labels], List[Labels]]
|
Tuple |
Source code in sleap_nn/data/splitting.py
split_labels_train_val(source, *, split_by, n_folds, fold, seed)
¶
Partition a single sio.Labels into (train, val) by a group key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
Labels
|
The |
required |
split_by
|
str
|
One of |
required |
n_folds
|
int
|
Number of CV folds; the val partition is |
required |
fold
|
int
|
Which fold (0-based) to hold out as validation. |
required |
seed
|
int
|
Random seed for the (shuffled) splitter. |
required |
Returns:
| Type | Description |
|---|---|
Tuple[Labels, Labels]
|
Tuple of new |
Source code in sleap_nn/data/splitting.py
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 | |