data_config
sleap_nn.config.data_config
¶
Serializable configuration classes for specifying all data configuration parameters.
These configuration classes are intended to specify all the parameters required to initialize the data config.
Classes:
| Name | Description |
|---|---|
AugmentationConfig |
Configuration of Augmentation. |
DataConfig |
Data configuration. |
GeometricConfig |
Configuration of Geometric (Optional). |
IdentityConfig |
Declared identity-equality semantics for the |
IntensityConfig |
Configuration of Intensity (Optional). |
PreprocessingConfig |
Configuration of Preprocessing. |
SplitConfig |
Group-aware train/val split, decided before training. |
TilingConfig |
Configuration of tiled training/inference (Phase 0/A). |
Functions:
| Name | Description |
|---|---|
data_mapper |
Maps the legacy data configuration to the new data configuration. |
validate_accumulator_device |
Ensure the tiling accumulator device is a supported value. |
validate_blend |
Ensure the tiling blend window is a supported mode. |
validate_fg_fraction |
nnU-Net foreground oversample fraction: 0.0 <= value < 1.0 (never 1.0). |
validate_optional_nonneg_int |
Allow None or a non-negative int (e.g. |
validate_optional_positive_int |
Allow None or a strictly-positive int. |
validate_proportion |
General Proportion Validation. |
validate_sampling |
Ensure the tiling sampling strategy is a supported value. |
validate_test_file_path |
Validate test_file_path to accept str or List[str]. |
AugmentationConfig
¶
Configuration of Augmentation.
Attributes:
| Name | Type | Description |
|---|---|---|
intensity |
Optional[IntensityConfig]
|
Configuration options for intensity-based augmentations like brightness, contrast, etc. If None, no intensity augmentations will be applied. |
geometric |
Optional[GeometricConfig]
|
Configuration options for geometric augmentations like rotation, scaling, translation etc. If None, no geometric augmentations will be applied. |
Source code in sleap_nn/config/data_config.py
DataConfig
¶
Data configuration.
Attributes:
| Name | Type | Description |
|---|---|---|
train_labels_path |
Optional[List[str]]
|
(List[str]) List of paths to training data ( |
val_labels_path |
Optional[List[str]]
|
(List[str]) List of paths to validation data ( |
validation_fraction |
float
|
(float) Float between 0 and 1 specifying the fraction of the training set to sample for generating the validation set. The remaining labeled frames will be left in the training set. If the |
use_same_data_for_val |
bool
|
(bool) If |
test_file_path |
Optional[Any]
|
(str or List[str]) Path or list of paths to test dataset(s) ( |
provider |
str
|
(str) Provider class to read the input sleap files. Only "LabelsReader" is currently supported for the training pipeline. Default: |
user_instances_only |
bool
|
(bool) |
data_pipeline_fw |
str
|
(str) Framework to create the data loaders. One of [ |
cache_img_path |
Optional[str]
|
(str) Path to save |
use_existing_imgs |
bool
|
(bool) Use existing train and val images/ chunks in the |
delete_cache_imgs_after_training |
bool
|
(bool) If |
parallel_caching |
bool
|
(bool) If |
cache_workers |
int
|
(int) Number of worker threads for parallel caching. If 0, uses min(4, cpu_count). Default: |
preprocessing |
PreprocessingConfig
|
Configuration options related to data preprocessing. |
use_augmentations_train |
bool
|
(bool) True if the data augmentation should be applied to the training data, else False. Default: |
augmentation_config |
Optional[AugmentationConfig]
|
Configurations related to augmentation. (only if |
use_negative_frames |
bool
|
(bool) If |
negative_loss_weight |
float
|
(float) Relative weight applied to the loss for negative samples. Must be > 0.
Values < 1 down-weight negatives; values > 1 up-weight them. Only has effect when
|
skeletons |
Optional[list]
|
skeleton configuration for the |
split |
Optional[SplitConfig]
|
(Optional[SplitConfig]) Group-aware train/val split decided before training.
When set and |
centroids_from_masks |
Optional[str]
|
(str) Derive |
Source code in sleap_nn/config/data_config.py
GeometricConfig
¶
Configuration of Geometric (Optional).
Attributes:
| Name | Type | Description |
|---|---|---|
rotation_min |
float
|
(float) Minimum rotation angle in degrees. A random angle in (rotation_min, rotation_max) will be sampled and applied to both images and keypoints. Set to 0 to disable rotation augmentation. Default: |
rotation_max |
float
|
(float) Maximum rotation angle in degrees. A random angle in (rotation_min, rotation_max) will be sampled and applied to both images and keypoints. Set to 0 to disable rotation augmentation. Default: |
rotation_p |
Optional[float]
|
(float, optional) Probability of applying random rotation independently. If set, rotation is applied separately from scale/translate. If |
scale_min |
float
|
(float) Minimum scaling factor. If scale_min and scale_max are provided, the scale is randomly sampled from the range scale_min <= scale <= scale_max for isotropic scaling. Default: |
scale_max |
float
|
(float) Maximum scaling factor. If scale_min and scale_max are provided, the scale is randomly sampled from the range scale_min <= scale <= scale_max for isotropic scaling. Default: |
scale_p |
Optional[float]
|
(float, optional) Probability of applying random scaling independently. If set, scaling is applied separately from rotation/translate. If |
translate_width |
float
|
(float) Maximum absolute fraction for horizontal translation. For example, if translate_width=a, then horizontal shift is randomly sampled in the range -img_width * a < dx < img_width * a. Will not translate by default. Default: |
translate_height |
float
|
(float) Maximum absolute fraction for vertical translation. For example, if translate_height=a, then vertical shift is randomly sampled in the range -img_height * a < dy < img_height * a. Will not translate by default. Default: |
translate_p |
Optional[float]
|
(float, optional) Probability of applying random translation independently. If set, translation is applied separately from rotation/scale. If |
affine_p |
float
|
(float) Probability of applying random affine transformations (rotation, scale, translate bundled together). Used for backwards compatibility when individual |
erase_scale_min |
float
|
(float) Minimum value of range of proportion of erased area against input image. Default: |
erase_scale_max |
float
|
(float) Maximum value of range of proportion of erased area against input image. Default: |
erase_ratio_min |
float
|
(float) Minimum value of range of aspect ratio of erased area. Default: |
erase_ratio_max |
float
|
(float) Maximum value of range of aspect ratio of erased area. Default: |
erase_p |
float
|
(float) Probability of applying random erase. Default: |
mixup_lambda_min |
float
|
(float) Minimum mixup strength value. Default: |
mixup_lambda_max |
float
|
(float) Maximum mixup strength value. Default: |
mixup_p |
float
|
(float) Probability of applying random mixup v2. Default: |
flip_p |
float
|
(float) Probability of mirroring the image and keypoints left/right ( |
Source code in sleap_nn/config/data_config.py
IdentityConfig
¶
Declared identity-equality semantics for the embedding model type.
Each positives/negatives source silently asserts "same/different animal". These
fields DECLARE what the track labels mean so the objective can validate them
(e.g. positives.scope=global_id requires track_names_are_global=True).
Attributes:
| Name | Type | Description |
|---|---|---|
tracks_are_proofread |
bool
|
(bool) Tracks are swap-free within a video. Gates
|
track_names_are_global |
bool
|
(bool) The same track name means the same animal
across videos. Gates |
detections_deduplicated |
bool
|
(bool) No duplicate/over-segmented detection per
frame. Gates |
Source code in sleap_nn/config/data_config.py
IntensityConfig
¶
Configuration of Intensity (Optional).
Attributes:
| Name | Type | Description |
|---|---|---|
uniform_noise_min |
float
|
(float) Minimum value for uniform noise (0-1 scale, multiplied by 255 internally). Default: |
uniform_noise_max |
float
|
(float) Maximum value for uniform noise (0-1 scale, multiplied by 255 internally). Default: |
uniform_noise_p |
float
|
(float) Probability of applying random uniform noise. Default: |
gaussian_noise_mean |
float
|
(float) The mean of the gaussian noise distribution (0-1 scale, multiplied by 255 internally). Default: |
gaussian_noise_std |
float
|
(float) The standard deviation of the gaussian noise distribution (0-1 scale, multiplied by 255 internally). Default: |
gaussian_noise_p |
float
|
(float) Probability of applying random gaussian noise. Default: |
contrast_min |
float
|
(float) Minimum contrast factor to apply. Default: |
contrast_max |
float
|
(float) Maximum contrast factor to apply. Default: |
contrast_p |
float
|
(float) Probability of applying random contrast. Default: |
brightness_min |
float
|
(float) Minimum brightness factor to apply. Default: |
brightness_max |
float
|
(float) Maximum brightness factor to apply. Default: |
brightness_p |
float
|
(float) Probability of applying random brightness. Default: |
Source code in sleap_nn/config/data_config.py
PreprocessingConfig
¶
Configuration of Preprocessing.
Attributes:
| Name | Type | Description |
|---|---|---|
ensure_rgb |
bool
|
(bool) True if the input image should have 3 channels (RGB image). If input has only one channel when this is set to |
ensure_grayscale |
bool
|
(bool) True if the input image should only have a single channel. If input has three channels (RGB) and this is set to True, then we convert the image to grayscale (single-channel) image. If the source image has only one channel and this is set to False, then we retain the single channel input. Default: |
max_height |
Optional[int]
|
(int) Maximum height the original image should be resized and padded to. If not provided, the original image size will be retained. Default: |
max_width |
Optional[int]
|
(int) Maximum width the original image should be resized and padded to. If not provided, the original image size will be retained. Default: |
scale |
float
|
(float) Factor to resize the image dimensions by, specified as a float. Default: |
crop_size |
Optional[int]
|
(int) Crop size of each instance for centered-instance model. If |
min_crop_size |
Optional[int]
|
(int) Minimum crop size to be used if |
crop_padding |
Optional[int]
|
(int) Padding in pixels to add around the instance bounding box when computing crop size.
If |
tiling |
TilingConfig
|
Configuration of tiled training/inference. Inert unless |
burn_in |
bool
|
(bool) For the |
background_fill |
str
|
(str) Fill value for masked-out background when |
crop_centering |
str
|
(str) For the |
Methods:
| Name | Description |
|---|---|
validate_scale |
Scale Validation. |
Source code in sleap_nn/config/data_config.py
validate_scale()
¶
Scale Validation.
Ensures PreprocessingConfig's scale is a float>=0 or list of floats>=0
Source code in sleap_nn/config/data_config.py
SplitConfig
¶
Group-aware train/val split, decided before training.
For the embedding 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. When set on DataConfig.split (and no explicit
val_labels_path is provided), the trainer partitions the training labels by
split_by instead of the default frame-level random validation_fraction split.
Attributes:
| Name | Type | Description |
|---|---|---|
split_by |
str
|
(str) Group key for the partition. One of:
|
n_folds |
int
|
(int) Number of CV folds; the val partition is |
fold |
int
|
(int) Which fold (0-based) to hold out as validation. Default: |
seed |
int
|
(int) Random seed for the (shuffled) splitter. Default: |
Source code in sleap_nn/config/data_config.py
TilingConfig
¶
Configuration of tiled training/inference (Phase 0/A).
Explicit opt-in only (enabled=True). Square tiles, constant-zero padding.
Geometry (tile_size, overlap) is auto-sized from labels x backbone margin at
train setup and written back into this config (persisted in training_config.yaml),
then read + parity-checked at inference. Unsupported with pretrained backbones and
with ClassVectorsHead / multi_class_topdown models (see check_tiling).
Attributes:
| Name | Type | Description |
|---|---|---|
enabled |
bool
|
(bool) If |
tile_size |
Optional[int]
|
(int) SQUARE tile side length in pixels. If |
overlap |
Optional[int]
|
(int) Tile overlap in pixels. If |
min_overlap_fraction |
float
|
(float) Minimum overlap as a fraction of |
blend |
str
|
(str) Merge window for stitching tile predictions. One of ['gaussian', 'pyramid', 'constant']. Default: |
sigma_scale |
float
|
(float) Per-axis std of the Gaussian importance window as a fraction of the tile side (std = sigma_scale * tile). Must be in (0.0, 1.0]. Default: |
tile_batch_size |
Optional[int]
|
(int) Number of tiles forwarded per backend call at inference. Manual knob; a conservative default is used when |
accumulator_device |
str
|
(str) Device for the per-frame ACC/CNT merge buffers. One of ['auto', 'cpu', 'cuda']; 'auto' predicts placement and falls back to CPU on OOM. Default: |
cpu_thresh |
float
|
(float) Spill ACC/CNT to CPU when the buffers would exceed this fraction of free GPU memory. Must be in [0.0, 1.0]. Default: |
sampling |
str
|
(str) Tile sampling strategy. 'foreground' (train, object-aware) or 'grid' (val/debug, full-coverage). Default: |
tile_fg_fraction |
float
|
(float) Fraction of sampled train tiles forced to contain an object (nnU-Net oversampling). Must be in [0.0, 1.0) (never 1.0). Default: |
samples_per_frame |
Optional[int]
|
(int) Number of tiles emitted per decoded frame as a worker-aligned block. If |
center_jitter |
float
|
(float) Foreground-tile center jitter as a fraction of tile/2. Must be in [0.0, 1.0]. Default: |
min_visible_keypoints |
int
|
(int) Keep an instance in a tile only if at least this many of its keypoints fall inside the tile. Must be >= 0. Default: |
steps_per_epoch |
Optional[int]
|
(int) Decouples the TRAIN epoch length from tile count. Validation is always full-coverage (not decoupled). If |
full_frame_pass |
bool
|
(bool) Full-image mixing pass. DECLARED but INERT in Phase 0/A (wired in Phase C). Default: |
Source code in sleap_nn/config/data_config.py
data_mapper(legacy_config)
¶
Maps the legacy data configuration to the new data configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
legacy_config
|
dict
|
A dictionary containing the legacy data configuration. |
required |
Returns:
| Type | Description |
|---|---|
DataConfig
|
An instance of |
Source code in sleap_nn/config/data_config.py
455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 | |
validate_accumulator_device(instance, attribute, value)
¶
Ensure the tiling accumulator device is a supported value.
Source code in sleap_nn/config/data_config.py
validate_blend(instance, attribute, value)
¶
Ensure the tiling blend window is a supported mode.
Source code in sleap_nn/config/data_config.py
validate_fg_fraction(instance, attribute, value)
¶
nnU-Net foreground oversample fraction: 0.0 <= value < 1.0 (never 1.0).
Source code in sleap_nn/config/data_config.py
validate_optional_nonneg_int(instance, attribute, value)
¶
Allow None or a non-negative int (e.g. overlap).
Source code in sleap_nn/config/data_config.py
validate_optional_positive_int(instance, attribute, value)
¶
Allow None or a strictly-positive int.
Used for tile_size, tile_batch_size, samples_per_frame, steps_per_epoch.
Source code in sleap_nn/config/data_config.py
validate_proportion(instance, attribute, value)
¶
General Proportion Validation.
Ensures all proportions are a 0<=float<=1.0
Source code in sleap_nn/config/data_config.py
validate_sampling(instance, attribute, value)
¶
Ensure the tiling sampling strategy is a supported value.
Source code in sleap_nn/config/data_config.py
validate_test_file_path(instance, attribute, value)
¶
Validate test_file_path to accept str or List[str].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
instance
|
The instance being validated. |
required | |
attribute
|
The attribute being validated. |
required | |
value
|
The value to validate. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If value is not None, str, or list of strings. |