sleap.nn.data.training¶
Transformers and utilities for training-related operations.
-
class
sleap.nn.data.training.
KeyMapper
(key_maps)[source]¶ Maps example keys to specified outputs.
This is useful for transforming examples into tuples that map onto specific layer names for training.
-
key_maps
¶ Dictionary or list of dictionaries with string keys and values of the form: {input_key: output_key}. If a list, the examples will be in tuples in the same order.
-
property
input_keys
¶ Return the keys that incoming elements are expected to have.
-
property
output_keys
¶ Return the keys that outgoing elements will have. These may be nested.
-
transform_dataset
(ds_input: tensorflow.python.data.ops.dataset_ops.DatasetV2) → tensorflow.python.data.ops.dataset_ops.DatasetV2[source]¶ Create a dataset with input keys mapped to new key names.
- Parameters
ds_input – Any tf.data.Dataset that generates examples as a dictionary of tensors with the keys in input_keys.
- Returns
A dataset that generates examples with the tensors in input_keys mapped to keys in output_keys according to the structure in key_maps.
-
-
sleap.nn.data.training.
split_labels
(labels: sleap.io.dataset.Labels, split_fractions: Sequence[float]) → Tuple[sleap.io.dataset.Labels][source]¶ Split a sleap.Labels into multiple new ones with random subsets of the data.
- Parameters
labels – An instance of sleap.Labels.
split_fractions – One or more floats between 0 and 1 that specify the fraction of examples that should be in each dataset. These should add up to <= 1.0. Fractions of less than 1 element will be rounded up to ensure that is at least 1 element in each split. One of the fractions may be -1 to indicate that it should contain all elements left over from the other splits.
- Returns
A tuple of new sleap.Labels instances of the same length as split_fractions.
- Raises
ValueError – If more than one split fraction is specified as -1.
ValueError – If the splits add up to more than the total available examples.
Note
Sampling is done without replacement.
-
sleap.nn.data.training.
split_labels_reader
(labels_reader: sleap.nn.data.providers.LabelsReader, split_fractions: Sequence[float]) → Tuple[sleap.nn.data.providers.LabelsReader][source]¶ Split a LabelsReader into multiple new ones with random subsets of the data.
- Parameters
labels_reader – An instance of sleap.nn.data.providers.LabelsReader. This is a provider that generates datasets that contain elements read from a sleap.Labels instance.
split_fractions – One or more floats between 0 and 1 that specify the fraction of examples that should be in each dataset. These should add up to <= 1.0. Fractions of less than 1 element will be rounded up to ensure that is at least 1 element in each split. One of the fractions may be -1 to indicate that it should contain all elements left over from the other splits.
- Returns
A tuple of LabelsReader instances of the same length as split_fractions. The indices will be stored in the example_indices in each LabelsReader instance.
The actual sleap.Labels instance will be the same for each instance, only the example_indices that are iterated over will change across splits.
If the input labels_reader already has example_indices, a subset of these will be sampled to generate the splits.
- Raises
ValueError – If more than one split fraction is specified as -1.
ValueError – If the splits add up to more than the total available examples.
Note
Sampling is done without replacement.