Skip to content

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 embedding model type.

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. overlap).

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
@define
class AugmentationConfig:
    """Configuration of Augmentation.

    Attributes:
        intensity: Configuration options for intensity-based augmentations like brightness, contrast, etc. If None, no intensity augmentations will be applied.
        geometric: Configuration options for geometric augmentations like rotation, scaling, translation etc. If None, no geometric augmentations will be applied.
    """

    intensity: Optional[IntensityConfig] = None
    geometric: Optional[GeometricConfig] = None

DataConfig

Data configuration.

Attributes:

Name Type Description
train_labels_path Optional[List[str]]

(List[str]) List of paths to training data (.slp file(s)). Default: None.

val_labels_path Optional[List[str]]

(List[str]) List of paths to validation data (.slp file(s)). Default: None.

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 validation_labels are already specified, this has no effect. Default: 0.1.

use_same_data_for_val bool

(bool) If True, use the same data for both training and validation (train = val). Useful for intentional overfitting on small datasets. When enabled, val_labels_path and validation_fraction are ignored. Default: False.

test_file_path Optional[Any]

(str or List[str]) Path or list of paths to test dataset(s) (.slp file(s) or .mp4 file(s)). Note: This is used only with CLI to get evaluation on test set after training is completed. Default: None.

provider str

(str) Provider class to read the input sleap files. Only "LabelsReader" is currently supported for the training pipeline. Default: "LabelsReader".

user_instances_only bool

(bool) True if only user labeled instances should be used for training. If False, both user labeled and predicted instances would be used. Default: True.

data_pipeline_fw str

(str) Framework to create the data loaders. One of [torch_dataset, torch_dataset_cache_img_memory, torch_dataset_cache_img_disk]. Default: "torch_dataset". (Note: When using torch_dataset, num_workers in trainer_config should be set to 0 as multiprocessing doesn't work with pickling video backends.)

cache_img_path Optional[str]

(str) Path to save .jpg images created with torch_dataset_cache_img_disk data pipeline framework. If None, the path provided in trainer_config.save_ckpt is used. The train_imgs and val_imgs dirs are created inside this path. Default: None.

use_existing_imgs bool

(bool) Use existing train and val images/ chunks in the cache_img_path for torch_dataset_cache_img_disk frameworks. If True, the cache_img_path should have train_imgs and val_imgs dirs. Default: False.

delete_cache_imgs_after_training bool

(bool) If False, the images (torch_dataset_cache_img_disk) are retained after training. Else, the files are deleted. Default: True.

parallel_caching bool

(bool) If True, use parallel processing to cache images (significantly faster for large datasets). Default: True.

cache_workers int

(int) Number of worker threads for parallel caching. If 0, uses min(4, cpu_count). Default: 0.

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: True.

augmentation_config Optional[AugmentationConfig]

Configurations related to augmentation. (only if use_augmentations_train is True)

use_negative_frames bool

(bool) If True, include all user-confirmed negative frames (labels.negative_frames) in the training set. These are frames the user explicitly marked as containing no instances. They produce all-zero confidence maps, teaching the model not to hallucinate detections on empty backgrounds. Use negative_loss_weight to control the relative importance of negative vs positive samples. Default: False.

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 use_negative_frames is True. Default: 1.0.

skeletons Optional[list]

skeleton configuration for the .slp file. This will be pulled from the train dataset and saved to the training_config.yaml

split Optional[SplitConfig]

(Optional[SplitConfig]) Group-aware train/val split decided before training. When set and val_labels_path is not provided, the trainer partitions the training labels by the configured group key (frame/video/ identity) instead of the default frame-level random validation_fraction split. Default: None (unchanged default behavior).

centroids_from_masks Optional[str]

(str) Derive UserCentroid annotations from the labels' segmentation masks at load time, so a MASK-ONLY dataset (no pose annotations at all) can train a centroid model. The value names the derivation method — center_of_mass or bbox_center, the two sio.SegmentationMask.to_centroid offers — and None (default) disables it. (geometric_median is defined over a point set and does not apply to masks; it is available for pose-derived centroids via centroid_method.) Frames that already carry user centroids are left alone. Once derived, the ordinary centroid_source="user" path takes over unchanged; nothing downstream knows the centroids came from masks. Default: None.

Source code in sleap_nn/config/data_config.py
@define
class DataConfig:
    """Data configuration.

    Attributes:
        train_labels_path: (List[str]) List of paths to training data (`.slp` file(s)). *Default*: `None`.
        val_labels_path: (List[str]) List of paths to validation data (`.slp` file(s)). *Default*: `None`.
        validation_fraction: (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 `validation_labels` are already specified, this has no effect. *Default*: `0.1`.
        use_same_data_for_val: (bool) If `True`, use the same data for both training and validation (train = val). Useful for intentional overfitting on small datasets. When enabled, `val_labels_path` and `validation_fraction` are ignored. *Default*: `False`.
        test_file_path: (str or List[str]) Path or list of paths to test dataset(s) (`.slp` file(s) or `.mp4` file(s)). *Note*: This is used only with CLI to get evaluation on test set after training is completed. *Default*: `None`.
        provider: (str) Provider class to read the input sleap files. Only "LabelsReader" is currently supported for the training pipeline. *Default*: `"LabelsReader"`.
        user_instances_only: (bool) `True` if only user labeled instances should be used for training. If `False`, both user labeled and predicted instances would be used. *Default*: `True`.
        data_pipeline_fw: (str) Framework to create the data loaders. One of [`torch_dataset`, `torch_dataset_cache_img_memory`, `torch_dataset_cache_img_disk`]. *Default*: `"torch_dataset"`. (Note: When using `torch_dataset`, `num_workers` in `trainer_config` should be set to 0 as multiprocessing doesn't work with pickling video backends.)
        cache_img_path: (str) Path to save `.jpg` images created with `torch_dataset_cache_img_disk` data pipeline framework. If `None`, the path provided in `trainer_config.save_ckpt` is used. The `train_imgs` and `val_imgs` dirs are created inside this path. *Default*: `None`.
        use_existing_imgs: (bool) Use existing train and val images/ chunks in the `cache_img_path` for `torch_dataset_cache_img_disk` frameworks. If `True`, the `cache_img_path` should have `train_imgs` and `val_imgs` dirs. *Default*: `False`.
        delete_cache_imgs_after_training: (bool) If `False`, the images (torch_dataset_cache_img_disk) are retained after training. Else, the files are deleted. *Default*: `True`.
        parallel_caching: (bool) If `True`, use parallel processing to cache images (significantly faster for large datasets). *Default*: `True`.
        cache_workers: (int) Number of worker threads for parallel caching. If 0, uses min(4, cpu_count). *Default*: `0`.
        preprocessing: Configuration options related to data preprocessing.
        use_augmentations_train: (bool) True if the data augmentation should be applied to the training data, else False. *Default*: `True`.
        augmentation_config: Configurations related to augmentation. (only if `use_augmentations_train` is `True`)
        use_negative_frames: (bool) If ``True``, include all user-confirmed negative frames
            (``labels.negative_frames``) in the training set. These are frames the user explicitly
            marked as containing no instances. They produce all-zero confidence maps, teaching the model
            not to hallucinate detections on empty backgrounds. Use ``negative_loss_weight`` to control
            the relative importance of negative vs positive samples. *Default*: ``False``.
        negative_loss_weight: (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
            ``use_negative_frames`` is ``True``. *Default*: `1.0`.
        skeletons: skeleton configuration for the `.slp` file. This will be pulled from the train dataset and saved to the `training_config.yaml`
        split: (Optional[SplitConfig]) Group-aware train/val split decided before training.
            When set and `val_labels_path` is not provided, the trainer
            partitions the training labels by the configured group key (`frame`/`video`/
            `identity`) instead of the default frame-level random `validation_fraction`
            split. *Default*: `None` (unchanged default behavior).
        centroids_from_masks: (str) Derive `UserCentroid` annotations from the labels'
            segmentation masks at load time, so a MASK-ONLY dataset (no pose
            annotations at all) can train a centroid model. The value names the
            derivation method — `center_of_mass` or `bbox_center`, the two
            `sio.SegmentationMask.to_centroid` offers — and `None` (default)
            disables it. (`geometric_median` is defined over a point set and does
            not apply to masks; it is available for pose-derived centroids via
            `centroid_method`.) Frames that
            already carry user centroids are left alone. Once derived, the ordinary
            `centroid_source="user"` path takes over unchanged; nothing downstream
            knows the centroids came from masks. *Default*: `None`.
    """

    train_labels_path: Optional[List[str]] = None
    val_labels_path: Optional[List[str]] = None  # TODO : revisit MISSING!
    validation_fraction: float = 0.1
    use_same_data_for_val: bool = False
    test_file_path: Optional[Any] = field(
        default=None, validator=validate_test_file_path
    )
    provider: str = "LabelsReader"
    user_instances_only: bool = True
    data_pipeline_fw: str = "torch_dataset"
    cache_img_path: Optional[str] = None
    use_existing_imgs: bool = False
    delete_cache_imgs_after_training: bool = True
    parallel_caching: bool = True
    cache_workers: int = 0
    preprocessing: PreprocessingConfig = field(factory=PreprocessingConfig)
    use_augmentations_train: bool = True
    augmentation_config: Optional[AugmentationConfig] = field(
        factory=lambda: AugmentationConfig(geometric=GeometricConfig())
    )
    use_negative_frames: bool = False
    negative_loss_weight: float = field(default=1.0, validator=validators.gt(0))
    skeletons: Optional[list] = None
    identity: Optional[IdentityConfig] = None
    split: Optional[SplitConfig] = None
    centroids_from_masks: Optional[str] = None

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: -15.0.

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: 15.0.

rotation_p Optional[float]

(float, optional) Probability of applying random rotation independently. If set, rotation is applied separately from scale/translate. If None, falls back to affine_p for bundled behavior. Default: 1.0.

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: 0.9.

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: 1.1.

scale_p Optional[float]

(float, optional) Probability of applying random scaling independently. If set, scaling is applied separately from rotation/translate. If None, falls back to affine_p for bundled behavior. Default: 1.0.

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: 0.0.

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: 0.0.

translate_p Optional[float]

(float, optional) Probability of applying random translation independently. If set, translation is applied separately from rotation/scale. If None, falls back to affine_p for bundled behavior. Default: None.

affine_p float

(float) Probability of applying random affine transformations (rotation, scale, translate bundled together). Used for backwards compatibility when individual *_p params are not set. Default: 0.0.

erase_scale_min float

(float) Minimum value of range of proportion of erased area against input image. Default: 0.0001.

erase_scale_max float

(float) Maximum value of range of proportion of erased area against input image. Default: 0.01.

erase_ratio_min float

(float) Minimum value of range of aspect ratio of erased area. Default: 1.0.

erase_ratio_max float

(float) Maximum value of range of aspect ratio of erased area. Default: 1.0.

erase_p float

(float) Probability of applying random erase. Default: 1.0.

mixup_lambda_min float

(float) Minimum mixup strength value. Default: 0.01.

mixup_lambda_max float

(float) Maximum mixup strength value. Default: 0.05.

mixup_p float

(float) Probability of applying random mixup v2. Default: 0.0.

flip_p float

(float) Probability of mirroring the image and keypoints left/right (x' = (W-1) - x). When applied, left/right symmetric body parts are swapped using the skeleton's symmetries so labels stay correct. Correctness note: if the skeleton has no symmetries, flipping is only valid when the animal is truly left/right symmetric in labeling; a warning is emitted otherwise. Default: 0.0 (disabled).

Source code in sleap_nn/config/data_config.py
@define
class GeometricConfig:
    """Configuration of Geometric (Optional).

    Attributes:
        rotation_min: (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*: `-15.0`.
        rotation_max: (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*: `15.0`.
        rotation_p: (float, optional) Probability of applying random rotation independently. If set, rotation is applied separately from scale/translate. If `None`, falls back to `affine_p` for bundled behavior. *Default*: `1.0`.
        scale_min: (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*: `0.9`.
        scale_max: (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*: `1.1`.
        scale_p: (float, optional) Probability of applying random scaling independently. If set, scaling is applied separately from rotation/translate. If `None`, falls back to `affine_p` for bundled behavior. *Default*: `1.0`.
        translate_width: (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*: `0.0`.
        translate_height: (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*: `0.0`.
        translate_p: (float, optional) Probability of applying random translation independently. If set, translation is applied separately from rotation/scale. If `None`, falls back to `affine_p` for bundled behavior. *Default*: `None`.
        affine_p: (float) Probability of applying random affine transformations (rotation, scale, translate bundled together). Used for backwards compatibility when individual `*_p` params are not set. *Default*: `0.0`.
        erase_scale_min: (float) Minimum value of range of proportion of erased area against input image. *Default*: `0.0001`.
        erase_scale_max: (float) Maximum value of range of proportion of erased area against input image. *Default*: `0.01`.
        erase_ratio_min: (float) Minimum value of range of aspect ratio of erased area. *Default*: `1.0`.
        erase_ratio_max: (float) Maximum value of range of aspect ratio of erased area. *Default*: `1.0`.
        erase_p: (float) Probability of applying random erase. *Default*: `1.0`.
        mixup_lambda_min: (float) Minimum mixup strength value. *Default*: `0.01`.
        mixup_lambda_max: (float) Maximum mixup strength value. *Default*: `0.05`.
        mixup_p: (float) Probability of applying random mixup v2. *Default*: `0.0`.
        flip_p: (float) Probability of mirroring the image and keypoints left/right (`x' = (W-1) - x`). When applied, left/right symmetric body parts are swapped using the skeleton's symmetries so labels stay correct. *Correctness note*: if the skeleton has no symmetries, flipping is only valid when the animal is truly left/right symmetric in labeling; a warning is emitted otherwise. *Default*: `0.0` (disabled).
    """

    rotation_min: float = field(default=-15.0, validator=validators.ge(-180))
    rotation_max: float = field(default=15.0, validator=validators.le(180))
    rotation_p: Optional[float] = field(default=1.0)
    scale_min: float = field(default=0.9, validator=validators.ge(0))
    scale_max: float = field(default=1.1, validator=validators.ge(0))
    scale_p: Optional[float] = field(default=1.0)
    translate_width: float = 0.0
    translate_height: float = 0.0
    translate_p: Optional[float] = field(default=None)
    affine_p: float = field(default=0.0, validator=validate_proportion)
    erase_scale_min: float = 0.0001
    erase_scale_max: float = 0.01
    erase_ratio_min: float = 1.0
    erase_ratio_max: float = 1.0
    erase_p: float = field(default=0.0, validator=validate_proportion)
    mixup_lambda_min: float = field(default=0.01, validator=validators.ge(0))
    mixup_lambda_max: float = field(default=0.05, validator=validators.le(1))
    mixup_p: float = field(default=0.0, validator=validate_proportion)
    flip_p: float = field(default=0.0, validator=validate_proportion)

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 positives.scope=tracklet (warn if False). Default: False.

track_names_are_global bool

(bool) The same track name means the same animal across videos. Gates positives.scope=global_id (error if False). Default: False.

detections_deduplicated bool

(bool) No duplicate/over-segmented detection per frame. Gates same_frame negatives (warn if False). Default: True.

Source code in sleap_nn/config/data_config.py
@define
class 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:
        tracks_are_proofread: (bool) Tracks are swap-free within a video. Gates
            `positives.scope=tracklet` (warn if False). *Default*: `False`.
        track_names_are_global: (bool) The same track name means the same animal
            across videos. Gates `positives.scope=global_id` (error if False).
            *Default*: `False`.
        detections_deduplicated: (bool) No duplicate/over-segmented detection per
            frame. Gates `same_frame` negatives (warn if False). *Default*: `True`.
    """

    tracks_are_proofread: bool = False
    track_names_are_global: bool = False
    detections_deduplicated: bool = True

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: 0.0.

uniform_noise_max float

(float) Maximum value for uniform noise (0-1 scale, multiplied by 255 internally). Default: 0.04.

uniform_noise_p float

(float) Probability of applying random uniform noise. Default: 0.0.

gaussian_noise_mean float

(float) The mean of the gaussian noise distribution (0-1 scale, multiplied by 255 internally). Default: 0.0.

gaussian_noise_std float

(float) The standard deviation of the gaussian noise distribution (0-1 scale, multiplied by 255 internally). Default: 0.02.

gaussian_noise_p float

(float) Probability of applying random gaussian noise. Default: 0.0.

contrast_min float

(float) Minimum contrast factor to apply. Default: 0.9.

contrast_max float

(float) Maximum contrast factor to apply. Default: 1.1.

contrast_p float

(float) Probability of applying random contrast. Default: 0.0.

brightness_min float

(float) Minimum brightness factor to apply. Default: 0.9.

brightness_max float

(float) Maximum brightness factor to apply. Default: 1.1.

brightness_p float

(float) Probability of applying random brightness. Default: 0.0.

Source code in sleap_nn/config/data_config.py
@define
class IntensityConfig:
    """Configuration of Intensity (Optional).

    Attributes:
        uniform_noise_min: (float) Minimum value for uniform noise (0-1 scale, multiplied by 255 internally). *Default*: `0.0`.
        uniform_noise_max: (float) Maximum value for uniform noise (0-1 scale, multiplied by 255 internally). *Default*: `0.04`.
        uniform_noise_p: (float) Probability of applying random uniform noise. *Default*: `0.0`.
        gaussian_noise_mean: (float) The mean of the gaussian noise distribution (0-1 scale, multiplied by 255 internally). *Default*: `0.0`.
        gaussian_noise_std: (float) The standard deviation of the gaussian noise distribution (0-1 scale, multiplied by 255 internally). *Default*: `0.02`.
        gaussian_noise_p: (float) Probability of applying random gaussian noise. *Default*: `0.0`.
        contrast_min: (float) Minimum contrast factor to apply. *Default*: `0.9`.
        contrast_max: (float) Maximum contrast factor to apply. *Default*: `1.1`.
        contrast_p: (float) Probability of applying random contrast. *Default*: `0.0`.
        brightness_min: (float) Minimum brightness factor to apply. *Default*: `0.9`.
        brightness_max: (float) Maximum brightness factor to apply. *Default*: `1.1`.
        brightness_p: (float) Probability of applying random brightness. *Default*: `0.0`.
    """

    uniform_noise_min: float = field(default=0.0, validator=validators.ge(0))
    uniform_noise_max: float = field(default=0.04, validator=validators.le(1))
    uniform_noise_p: float = field(default=0.0, validator=validate_proportion)
    gaussian_noise_mean: float = 0.0
    gaussian_noise_std: float = 0.02
    gaussian_noise_p: float = field(default=0.0, validator=validate_proportion)
    contrast_min: float = field(default=0.9, validator=validators.ge(0))
    contrast_max: float = field(default=1.1, validator=validators.ge(0))
    contrast_p: float = field(default=0.0, validator=validate_proportion)
    brightness_min: float = field(default=0.9, validator=validators.ge(0))
    brightness_max: float = field(default=1.1, validator=validators.le(2))
    brightness_p: float = field(default=0.0, validator=validate_proportion)

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 True, then the images from single-channel is replicated along the channel axis. If the image has three channels and this is set to False, then we retain the three channels. Default: False.

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: False.

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: None.

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: None.

scale float

(float) Factor to resize the image dimensions by, specified as a float. Default: 1.0.

crop_size Optional[int]

(int) Crop size of each instance for centered-instance model. If None, this would be automatically computed based on the largest instance in the sio.Labels file. If scale is provided, then the cropped image will be resized according to scale.Default: None.

min_crop_size Optional[int]

(int) Minimum crop size to be used if crop_size is None. Default: 100.

crop_padding Optional[int]

(int) Padding in pixels to add around the instance bounding box when computing crop size. If None, padding is auto-computed based on augmentation settings (rotation/scale). Only used when crop_size is None. Default: None.

tiling TilingConfig

Configuration of tiled training/inference. Inert unless tiling.enabled is True.

burn_in bool

(bool) For the embedding model type: burn the instance mask into the crop (background pixels set to background_fill) so the embedder sees only the masked instance. Default: False.

background_fill str

(str) Fill value for masked-out background when burn_in is True (embedding model type). One of black (the original mask-multiply; foreground mean / 0 in standardized space), grey (mid-grey), mean (foreground mean — equivalent to black for standardized inputs), or noise (per-pixel noise). Default: black.

crop_centering str

(str) For the embedding model type, what the fixed-square crop is centered on. auto (mask mode -> mask center-of-mass; pose mode -> head_configs.embedding.embedding.anchor_part with a mean-of-visible-nodes fallback), mask_com (force the mask center-of-mass), or bbox (the mask bounding-box midpoint, robust to concave masks whose COM lands off the instance). Only mask-mode centering is affected; pose-mode centering is driven by anchor_part. Default: auto.

Methods:

Name Description
validate_scale

Scale Validation.

Source code in sleap_nn/config/data_config.py
@define
class PreprocessingConfig:
    """Configuration of Preprocessing.

    Attributes:
        ensure_rgb: (bool) True if the input image should have 3 channels (RGB image). If input has only one channel when this is set to `True`, then the images from single-channel is replicated along the channel axis. If the image has three channels and this is set to False, then we retain the three channels. *Default*: `False`.
        ensure_grayscale: (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*: `False`.
        max_height: (int) Maximum height the original image should be resized and padded to. If not provided, the original image size will be retained. *Default*: `None`.
        max_width: (int) Maximum width the original image should be resized and padded to. If not provided, the original image size will be retained. *Default*: `None`.
        scale: (float) Factor to resize the image dimensions by, specified as a float. *Default*: `1.0`.
        crop_size: (int) Crop size of each instance for centered-instance model. If `None`, this would be automatically computed based on the largest instance in the `sio.Labels` file.
            If `scale` is provided, then the cropped image will be resized according to `scale`.*Default*: `None`.
        min_crop_size: (int) Minimum crop size to be used if `crop_size` is `None`. *Default*: `100`.
        crop_padding: (int) Padding in pixels to add around the instance bounding box when computing crop size.
            If `None`, padding is auto-computed based on augmentation settings (rotation/scale).
            Only used when `crop_size` is `None`. *Default*: `None`.
        tiling: Configuration of tiled training/inference. Inert unless `tiling.enabled` is `True`.
        burn_in: (bool) For the `embedding` model type: burn the instance mask into the
            crop (background pixels set to `background_fill`) so the embedder sees only
            the masked instance. *Default*: `False`.
        background_fill: (str) Fill value for masked-out background when `burn_in` is
            True (`embedding` model type). One of `black` (the original mask-multiply;
            foreground mean / 0 in standardized space), `grey` (mid-grey), `mean`
            (foreground mean — equivalent to `black` for standardized inputs), or
            `noise` (per-pixel noise). *Default*: `black`.
        crop_centering: (str) For the `embedding` model type, what the fixed-square crop
            is centered on. `auto` (mask mode -> mask center-of-mass; pose mode ->
            `head_configs.embedding.embedding.anchor_part` with a mean-of-visible-nodes
            fallback), `mask_com` (force the mask center-of-mass), or `bbox` (the mask
            bounding-box midpoint, robust to concave masks whose COM lands off the
            instance). Only `mask`-mode centering is affected; pose-mode centering is
            driven by `anchor_part`. *Default*: `auto`.
    """

    ensure_rgb: bool = False
    ensure_grayscale: bool = False
    max_height: Optional[int] = None
    max_width: Optional[int] = None
    scale: float = field(
        default=1.0, validator=lambda instance, attr, value: instance.validate_scale()
    )
    crop_size: Optional[int] = None
    min_crop_size: Optional[int] = 100  # to help app work in case of error
    crop_padding: Optional[int] = None
    tiling: TilingConfig = field(factory=TilingConfig)
    burn_in: bool = False
    background_fill: str = "black"
    crop_centering: str = "auto"

    def validate_scale(self):
        """Scale Validation.

        Ensures PreprocessingConfig's scale is a float>=0 or list of floats>=0
        """
        if isinstance(self.scale, float) and self.scale >= 0:
            return
        if isinstance(self.scale, list) and all(
            isinstance(x, float) and x >= 0 for x in self.scale
        ):
            return
        message = "PreprocessingConfig's scale must be a float or a list of floats."
        logger.error(message)
        raise ValueError(message)

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
def validate_scale(self):
    """Scale Validation.

    Ensures PreprocessingConfig's scale is a float>=0 or list of floats>=0
    """
    if isinstance(self.scale, float) and self.scale >= 0:
        return
    if isinstance(self.scale, list) and all(
        isinstance(x, float) and x >= 0 for x in self.scale
    ):
        return
    message = "PreprocessingConfig's scale must be a float or a list of floats."
    logger.error(message)
    raise ValueError(message)

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: frame (stratified-random over LabeledFrames, identity-balanced; both train and val contain all identities), video (hold out whole videos by sio video index), or identity (hold out whole track names; disjoint identity sets). Default: frame.

n_folds int

(int) Number of CV folds; the val partition is 1 / n_folds of the data. Default: 5.

fold int

(int) Which fold (0-based) to hold out as validation. Default: 0.

seed int

(int) Random seed for the (shuffled) splitter. Default: 0.

Source code in sleap_nn/config/data_config.py
@define
class 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:
        split_by: (str) Group key for the partition. One of:
            `frame` (stratified-random over `LabeledFrame`s, identity-balanced; both train
            and val contain all identities), `video` (hold out whole videos by sio video
            index), or `identity` (hold out whole track names; disjoint identity sets).
            *Default*: `frame`.
        n_folds: (int) Number of CV folds; the val partition is `1 / n_folds` of the data.
            *Default*: `5`.
        fold: (int) Which fold (0-based) to hold out as validation. *Default*: `0`.
        seed: (int) Random seed for the (shuffled) splitter. *Default*: `0`.
    """

    split_by: str = "frame"
    n_folds: int = 5
    fold: int = 0
    seed: int = 0

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 True, engage tiled training/inference. Explicit opt-in; there is no engagement heuristic. Default: False.

tile_size Optional[int]

(int) SQUARE tile side length in pixels. If None, auto-computed at train setup as a multiple of both the effective backbone max_stride and the head output_stride. Default: None.

overlap Optional[int]

(int) Tile overlap in pixels. If None, auto-sized from object extent / confmap sigma plus a fixed backbone context margin; a conservative default is used (with a warning) when labels are sparse. An explicit value always overrides. Default: None.

min_overlap_fraction float

(float) Minimum overlap as a fraction of tile_size, enforced (overlap raised if needed) in check_tiling. Must be in [0.0, 1.0]. Default: 0.25.

blend str

(str) Merge window for stitching tile predictions. One of ['gaussian', 'pyramid', 'constant']. Default: "gaussian".

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: 0.125.

tile_batch_size Optional[int]

(int) Number of tiles forwarded per backend call at inference. Manual knob; a conservative default is used when None (no auto-tuner). Default: None.

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: "auto".

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: 0.40.

sampling str

(str) Tile sampling strategy. 'foreground' (train, object-aware) or 'grid' (val/debug, full-coverage). Default: "foreground".

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: 0.5.

samples_per_frame Optional[int]

(int) Number of tiles emitted per decoded frame as a worker-aligned block. If None, a conservative default is used. Default: None.

center_jitter float

(float) Foreground-tile center jitter as a fraction of tile/2. Must be in [0.0, 1.0]. Default: 0.5.

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: 1.

steps_per_epoch Optional[int]

(int) Decouples the TRAIN epoch length from tile count. Validation is always full-coverage (not decoupled). If None, derived from the effective sample count. Default: None.

full_frame_pass bool

(bool) Full-image mixing pass. DECLARED but INERT in Phase 0/A (wired in Phase C). Default: False.

Source code in sleap_nn/config/data_config.py
@define
class 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:
        enabled: (bool) If `True`, engage tiled training/inference. Explicit opt-in; there is no engagement heuristic. *Default*: `False`.
        tile_size: (int) SQUARE tile side length in pixels. If `None`, auto-computed at train setup as a multiple of both the effective backbone max_stride and the head output_stride. *Default*: `None`.
        overlap: (int) Tile overlap in pixels. If `None`, auto-sized from object extent / confmap sigma plus a fixed backbone context margin; a conservative default is used (with a warning) when labels are sparse. An explicit value always overrides. *Default*: `None`.
        min_overlap_fraction: (float) Minimum overlap as a fraction of `tile_size`, enforced (overlap raised if needed) in `check_tiling`. Must be in [0.0, 1.0]. *Default*: `0.25`.
        blend: (str) Merge window for stitching tile predictions. One of ['gaussian', 'pyramid', 'constant']. *Default*: `"gaussian"`.
        sigma_scale: (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*: `0.125`.
        tile_batch_size: (int) Number of tiles forwarded per backend call at inference. Manual knob; a conservative default is used when `None` (no auto-tuner). *Default*: `None`.
        accumulator_device: (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*: `"auto"`.
        cpu_thresh: (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*: `0.40`.
        sampling: (str) Tile sampling strategy. 'foreground' (train, object-aware) or 'grid' (val/debug, full-coverage). *Default*: `"foreground"`.
        tile_fg_fraction: (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*: `0.5`.
        samples_per_frame: (int) Number of tiles emitted per decoded frame as a worker-aligned block. If `None`, a conservative default is used. *Default*: `None`.
        center_jitter: (float) Foreground-tile center jitter as a fraction of tile/2. Must be in [0.0, 1.0]. *Default*: `0.5`.
        min_visible_keypoints: (int) Keep an instance in a tile only if at least this many of its keypoints fall inside the tile. Must be >= 0. *Default*: `1`.
        steps_per_epoch: (int) Decouples the TRAIN epoch length from tile count. Validation is always full-coverage (not decoupled). If `None`, derived from the effective sample count. *Default*: `None`.
        full_frame_pass: (bool) Full-image mixing pass. DECLARED but INERT in Phase 0/A (wired in Phase C). *Default*: `False`.
    """

    enabled: bool = False
    tile_size: Optional[int] = field(
        default=None, validator=validate_optional_positive_int
    )
    overlap: Optional[int] = field(default=None, validator=validate_optional_nonneg_int)
    min_overlap_fraction: float = field(default=0.25, validator=validate_proportion)
    blend: str = field(default="gaussian", validator=validate_blend)
    sigma_scale: float = field(
        default=0.125, validator=[validators.gt(0), validators.le(1)]
    )
    tile_batch_size: Optional[int] = field(
        default=None, validator=validate_optional_positive_int
    )
    accumulator_device: str = field(
        default="auto", validator=validate_accumulator_device
    )
    cpu_thresh: float = field(default=0.40, validator=validate_proportion)
    sampling: str = field(default="foreground", validator=validate_sampling)
    tile_fg_fraction: float = field(default=0.5, validator=validate_fg_fraction)
    samples_per_frame: Optional[int] = field(
        default=None, validator=validate_optional_positive_int
    )
    center_jitter: float = field(default=0.5, validator=validate_proportion)
    min_visible_keypoints: int = field(default=1, validator=validators.ge(0))
    steps_per_epoch: Optional[int] = field(
        default=None, validator=validate_optional_positive_int
    )
    full_frame_pass: bool = False

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 DataConfig with the mapped configuration.

Source code in sleap_nn/config/data_config.py
def data_mapper(legacy_config: dict) -> DataConfig:
    """Maps the legacy data configuration to the new data configuration.

    Args:
        legacy_config: A dictionary containing the legacy data configuration.

    Returns:
        An instance of `DataConfig` with the mapped configuration.
    """
    legacy_config_data = legacy_config.get("data", {})
    legacy_config_optimization = legacy_config.get("optimization", {})
    train_labels_path = legacy_config_data.get("labels", {}).get(
        "training_labels", None
    )
    val_labels_path = legacy_config_data.get("labels", {}).get(
        "validation_labels", None
    )

    # get skeleton(s)
    json_skeletons = legacy_config_data.get("labels", {}).get("skeletons", None)
    skeletons_list = None
    if json_skeletons is not None:
        skeletons_list = []
        skeletons = SkeletonDecoder().decode(json_skeletons)
        skeletons = yaml.safe_load(SkeletonYAMLEncoder().encode(skeletons))
        for skl_name in skeletons.keys():
            skl = skeletons[skl_name]
            skl["name"] = skl_name
            skeletons_list.append(skl)

    data_cfg_args = {}
    preprocessing_args = {}
    intensity_args = {}
    geometric_args = {}

    if train_labels_path is not None:
        data_cfg_args["train_labels_path"] = [train_labels_path]
    if val_labels_path is not None:
        data_cfg_args["val_labels_path"] = [val_labels_path]
    if (
        legacy_config_data.get("labels", {}).get("validation_fraction", None)
        is not None
    ):
        data_cfg_args["validation_fraction"] = legacy_config_data["labels"][
            "validation_fraction"
        ]
    if legacy_config_data.get("labels", {}).get("test_labels", None) is not None:
        data_cfg_args["test_file_path"] = legacy_config_data["labels"]["test_labels"]

    # preprocessing
    if legacy_config_data.get("preprocessing", {}).get("ensure_rgb", None) is not None:
        preprocessing_args["ensure_rgb"] = legacy_config_data["preprocessing"][
            "ensure_rgb"
        ]
    if (
        legacy_config_data.get("preprocessing", {}).get("ensure_grayscale", None)
        is not None
    ):
        preprocessing_args["ensure_grayscale"] = legacy_config_data["preprocessing"][
            "ensure_grayscale"
        ]
    if (
        legacy_config_data.get("preprocessing", {}).get("target_height", None)
        is not None
    ):
        preprocessing_args["max_height"] = legacy_config_data["preprocessing"][
            "target_height"
        ]
    if (
        legacy_config_data.get("preprocessing", {}).get("target_width", None)
        is not None
    ):
        preprocessing_args["max_width"] = legacy_config_data["preprocessing"][
            "target_width"
        ]
    if (
        legacy_config_data.get("preprocessing", {}).get("input_scaling", None)
        is not None
    ):
        preprocessing_args["scale"] = legacy_config_data["preprocessing"][
            "input_scaling"
        ]
    if (
        legacy_config_data.get("instance_cropping", {}).get("crop_size", None)
        is not None
    ):
        size = legacy_config_data["instance_cropping"]["crop_size"]
        preprocessing_args["crop_size"] = size

    # augmentation
    if (
        legacy_config_optimization.get("augmentation_config", {}).get(
            "uniform_noise_min_val", None
        )
        is not None
    ):
        intensity_args["uniform_noise_min"] = max(
            legacy_config_optimization["augmentation_config"]["uniform_noise_min_val"],
            0.0,
        )

    if (
        legacy_config_optimization.get("augmentation_config", {}).get(
            "uniform_noise_max_val", None
        )
        is not None
    ):
        intensity_args["uniform_noise_max"] = min(
            legacy_config_optimization["augmentation_config"]["uniform_noise_max_val"],
            1.0,
        )

    if (
        legacy_config_optimization.get("augmentation_config", {}).get(
            "uniform_noise", None
        )
        is not None
    ):
        intensity_args["uniform_noise_p"] = float(
            legacy_config_optimization["augmentation_config"]["uniform_noise"]
        )

    if (
        legacy_config_optimization.get("augmentation_config", {}).get(
            "gaussian_noise_mean", None
        )
        is not None
    ):
        intensity_args["gaussian_noise_mean"] = legacy_config_optimization[
            "augmentation_config"
        ]["gaussian_noise_mean"]

    if (
        legacy_config_optimization.get("augmentation_config", {}).get(
            "gaussian_noise_stddev", None
        )
        is not None
    ):
        intensity_args["gaussian_noise_std"] = legacy_config_optimization[
            "augmentation_config"
        ]["gaussian_noise_stddev"]

    if (
        legacy_config_optimization.get("augmentation_config", {}).get(
            "gaussian_noise", None
        )
        is not None
    ):
        intensity_args["gaussian_noise_p"] = float(
            legacy_config_optimization["augmentation_config"]["gaussian_noise"]
        )

    if (
        legacy_config_optimization.get("augmentation_config", {}).get(
            "contrast_min_gamma", None
        )
        is not None
    ):
        intensity_args["contrast_min"] = max(
            legacy_config_optimization["augmentation_config"]["contrast_min_gamma"],
            0.0,
        )

    if (
        legacy_config_optimization.get("augmentation_config", {}).get(
            "contrast_max_gamma", None
        )
        is not None
    ):
        intensity_args["contrast_max"] = max(
            legacy_config_optimization["augmentation_config"]["contrast_max_gamma"],
            0.0,
        )

    if (
        legacy_config_optimization.get("augmentation_config", {}).get("contrast", None)
        is not None
    ):
        intensity_args["contrast_p"] = float(
            legacy_config_optimization["augmentation_config"]["contrast"]
        )

    if (
        legacy_config_optimization.get("augmentation_config", {}).get(
            "brightness_min_val", None
        )
        is not None
    ):
        intensity_args["brightness_min"] = min(
            max(
                legacy_config_optimization["augmentation_config"]["brightness_min_val"],
                0.0,
            ),
            2.0,
        )

    if (
        legacy_config_optimization.get("augmentation_config", {}).get(
            "brightness_max_val", None
        )
        is not None
    ):
        intensity_args["brightness_max"] = min(
            legacy_config_optimization["augmentation_config"]["brightness_max_val"], 2.0
        )  # kornia brightness_max can only be 2.0

    if (
        legacy_config_optimization.get("augmentation_config", {}).get(
            "brightness", None
        )
        is not None
    ):
        intensity_args["brightness_p"] = float(
            legacy_config_optimization["augmentation_config"]["brightness"]
        )

    if (
        legacy_config_optimization.get("augmentation_config", {}).get(
            "rotation_min_angle", None
        )
        is not None
    ):
        geometric_args["rotation_min"] = legacy_config_optimization[
            "augmentation_config"
        ]["rotation_min_angle"]

    if (
        legacy_config_optimization.get("augmentation_config", {}).get(
            "rotation_max_angle", None
        )
        is not None
    ):
        geometric_args["rotation_max"] = legacy_config_optimization[
            "augmentation_config"
        ]["rotation_max_angle"]

    if (
        legacy_config_optimization.get("augmentation_config", {}).get("scale_min", None)
        is not None
    ):
        geometric_args["scale_min"] = legacy_config_optimization["augmentation_config"][
            "scale_min"
        ]

    if (
        legacy_config_optimization.get("augmentation_config", {}).get("scale_max", None)
        is not None
    ):
        geometric_args["scale_max"] = legacy_config_optimization["augmentation_config"][
            "scale_max"
        ]

    if (
        legacy_config_optimization.get("augmentation_config", {}).get("scale", None)
        is not None
    ):
        geometric_args["scale_min"] = legacy_config_optimization["augmentation_config"][
            "scale_min"
        ]
        geometric_args["scale_max"] = legacy_config_optimization["augmentation_config"][
            "scale_max"
        ]

    if legacy_config_optimization.get("augmentation_config", {}).get(
        "random_flip", False
    ):
        if legacy_config_optimization["augmentation_config"].get(
            "flip_horizontal", True
        ):
            geometric_args["flip_p"] = 0.5
        else:
            logger.warning(
                "Legacy config has vertical flip (flip_horizontal=False) enabled; "
                "vertical flip is not supported in sleap-nn and will be dropped."
            )

    geometric_args["affine_p"] = (
        1.0
        if any(
            [
                legacy_config_optimization.get("augmentation_config", {}).get(
                    "rotate", False
                ),
                legacy_config_optimization.get("augmentation_config", {}).get(
                    "scale", False
                ),
            ]
        )
        else 0.0
    )

    data_cfg_args["preprocessing"] = PreprocessingConfig(**preprocessing_args)
    data_cfg_args["augmentation_config"] = AugmentationConfig(
        intensity=IntensityConfig(**intensity_args),
        geometric=GeometricConfig(**geometric_args),
    )

    data_cfg_args["skeletons"] = (
        skeletons_list
        if skeletons_list is not None and len(skeletons_list) > 0
        else None
    )

    return DataConfig(**data_cfg_args)

validate_accumulator_device(instance, attribute, value)

Ensure the tiling accumulator device is a supported value.

Source code in sleap_nn/config/data_config.py
def validate_accumulator_device(instance, attribute, value):
    """Ensure the tiling accumulator device is a supported value."""
    if value not in ("auto", "cpu", "cuda"):
        message = (
            "accumulator_device must be one of ['auto', 'cpu', 'cuda'], "
            f"got {value!r}"
        )
        logger.error(message)
        raise ValueError(message)

validate_blend(instance, attribute, value)

Ensure the tiling blend window is a supported mode.

Source code in sleap_nn/config/data_config.py
def validate_blend(instance, attribute, value):
    """Ensure the tiling blend window is a supported mode."""
    if value not in ("gaussian", "pyramid", "constant"):
        message = (
            f"blend must be one of ['gaussian', 'pyramid', 'constant'], got {value!r}"
        )
        logger.error(message)
        raise ValueError(message)

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
def validate_fg_fraction(instance, attribute, value):
    """nnU-Net foreground oversample fraction: 0.0 <= value < 1.0 (never 1.0)."""
    if not (0.0 <= value < 1.0):
        message = f"{attribute.name} must be in [0.0, 1.0) (never 1.0), got {value}"
        logger.error(message)
        raise ValueError(message)

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
def validate_optional_nonneg_int(instance, attribute, value):
    """Allow None or a non-negative int (e.g. `overlap`)."""
    if value is None:
        return
    if not (isinstance(value, int) and value >= 0):
        message = (
            f"{attribute.name} must be a non-negative integer or None, got {value!r}"
        )
        logger.error(message)
        raise ValueError(message)

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
def 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`.
    """
    if value is None:
        return
    if not (isinstance(value, int) and value > 0):
        message = f"{attribute.name} must be a positive integer or None, got {value!r}"
        logger.error(message)
        raise ValueError(message)

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
def validate_proportion(instance, attribute, value):
    """General Proportion Validation.

    Ensures all proportions are a 0<=float<=1.0
    """
    if not (0.0 <= value <= 1.0):
        message = f"{attribute.name} must be between 0.0 and 1.0, got {value}"
        logger.error(message)
        raise ValueError(message)

validate_sampling(instance, attribute, value)

Ensure the tiling sampling strategy is a supported value.

Source code in sleap_nn/config/data_config.py
def validate_sampling(instance, attribute, value):
    """Ensure the tiling sampling strategy is a supported value."""
    if value not in ("foreground", "grid"):
        message = f"sampling must be one of ['foreground', 'grid'], got {value!r}"
        logger.error(message)
        raise ValueError(message)

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.

Source code in sleap_nn/config/data_config.py
def validate_test_file_path(instance, attribute, value):
    """Validate test_file_path to accept str or List[str].

    Args:
        instance: The instance being validated.
        attribute: The attribute being validated.
        value: The value to validate.

    Raises:
        ValueError: If value is not None, str, or list of strings.
    """
    if value is None:
        return
    if isinstance(value, str):
        return
    if isinstance(value, (list, tuple)) and all(isinstance(p, str) for p in value):
        return
    message = f"{attribute.name} must be a string or list of strings, got {type(value).__name__}"
    logger.error(message)
    raise ValueError(message)