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.
Mask-only labels (e.g. the gerbil instance-segmentation data) carry detections on
lf.masks with lf.instances empty; identity grouping reads track names from
lf.masks in that case.
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
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 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 | |