sleap.nn.data.pipelines#
This module defines high level pipeline configurations from providers/transformers.
The Pipeline
class has the capability to create sequences of data I/O and processing
operations wrapped in a tf.data
-based pipeline.
This allows for convenient ways to configure individual variants of common pipelines, as well as to define training vs inference versions based on the same configurations.
- class sleap.nn.data.pipelines.BottomUpMultiClassPipeline(data_config: sleap.nn.config.data.DataConfig, optimization_config: sleap.nn.config.optimization.OptimizationConfig, confmaps_head: sleap.nn.heads.MultiInstanceConfmapsHead, class_maps_head: sleap.nn.heads.ClassMapsHead, offsets_head: Optional[sleap.nn.heads.OffsetRefinementHead] = None)[source]#
Pipeline builder for confidence maps and class maps models.
- data_config#
Data-related configuration.
- optimization_config#
Optimization-related configuration.
- confmaps_head#
Instantiated head describing the output confidence maps tensor.
- class_maps_head#
Instantiated head describing the output class maps tensor.
- offsets_head#
Optional head describing the offset refinement maps.
- Type
Optional[sleap.nn.heads.OffsetRefinementHead]
- make_base_pipeline(data_provider: sleap.nn.data.pipelines.Provider) sleap.nn.data.pipelines.Pipeline [source]#
Create base pipeline with input data only.
- Parameters
data_provider – A
Provider
that generates data examples, typically aLabelsReader
instance.- Returns
A
Pipeline
instance configured to produce input examples.
- make_training_pipeline(data_provider: sleap.nn.data.pipelines.Provider) sleap.nn.data.pipelines.Pipeline [source]#
Create full training pipeline.
- Parameters
data_provider – A
Provider
that generates data examples, typically aLabelsReader
instance.- Returns
A
Pipeline
instance configured to produce all data keys required for training.
Notes
This does not remap keys to model outputs. Use
KeyMapper
to pull out keys with the appropriate format for the instantiatedtf.keras.Model
.
- make_viz_pipeline(data_provider: sleap.nn.data.pipelines.Provider, keras_model: keras.engine.training.Model) sleap.nn.data.pipelines.Pipeline [source]#
Create visualization pipeline.
- Parameters
data_provider – A
Provider
that generates data examples, typically aLabelsReader
instance.keras_model – A
tf.keras.Model
that can be used for inference.
- Returns
A
Pipeline
instance configured to fetch data and run inference to generate predictions useful for visualization during training.
- class sleap.nn.data.pipelines.BottomUpPipeline(data_config: sleap.nn.config.data.DataConfig, optimization_config: sleap.nn.config.optimization.OptimizationConfig, confmaps_head: sleap.nn.heads.MultiInstanceConfmapsHead, pafs_head: sleap.nn.heads.PartAffinityFieldsHead, offsets_head: Optional[sleap.nn.heads.OffsetRefinementHead] = None)[source]#
Pipeline builder for confidence maps + part affinity fields models.
- data_config#
Data-related configuration.
- optimization_config#
Optimization-related configuration.
- confmaps_head#
Instantiated head describing the output confidence maps tensor.
- pafs_head#
Instantiated head describing the output PAFs tensor.
- offsets_head#
Optional head describing the offset refinement maps.
- Type
Optional[sleap.nn.heads.OffsetRefinementHead]
- make_base_pipeline(data_provider: sleap.nn.data.pipelines.Provider) sleap.nn.data.pipelines.Pipeline [source]#
Create base pipeline with input data only.
- Parameters
data_provider – A
Provider
that generates data examples, typically aLabelsReader
instance.- Returns
A
Pipeline
instance configured to produce input examples.
- make_training_pipeline(data_provider: sleap.nn.data.pipelines.Provider) sleap.nn.data.pipelines.Pipeline [source]#
Create full training pipeline.
- Parameters
data_provider – A
Provider
that generates data examples, typically aLabelsReader
instance.- Returns
A
Pipeline
instance configured to produce all data keys required for training.
Notes
This does not remap keys to model outputs. Use
KeyMapper
to pull out keys with the appropriate format for the instantiatedtf.keras.Model
.
- make_viz_pipeline(data_provider: sleap.nn.data.pipelines.Provider, keras_model: keras.engine.training.Model) sleap.nn.data.pipelines.Pipeline [source]#
Create visualization pipeline.
- Parameters
data_provider – A
Provider
that generates data examples, typically aLabelsReader
instance.keras_model – A
tf.keras.Model
that can be used for inference.
- Returns
A
Pipeline
instance configured to fetch data and run inference to generate predictions useful for visualization during training.
- class sleap.nn.data.pipelines.CentroidConfmapsPipeline(data_config: sleap.nn.config.data.DataConfig, optimization_config: sleap.nn.config.optimization.OptimizationConfig, centroid_confmap_head: sleap.nn.heads.CentroidConfmapsHead, offsets_head: Optional[sleap.nn.heads.OffsetRefinementHead] = None)[source]#
Pipeline builder for centroid confidence map models.
- data_config#
Data-related configuration.
- optimization_config#
Optimization-related configuration.
- centroid_confmap_head#
Instantiated head describing the output centroid confidence maps tensor.
- offsets_head#
Optional head describing the offset refinement maps.
- Type
Optional[sleap.nn.heads.OffsetRefinementHead]
- make_base_pipeline(data_provider: sleap.nn.data.pipelines.Provider) sleap.nn.data.pipelines.Pipeline [source]#
Create base pipeline with input data only.
- Parameters
data_provider – A
Provider
that generates data examples, typically aLabelsReader
instance.- Returns
A
Pipeline
instance configured to produce input examples.
- make_training_pipeline(data_provider: sleap.nn.data.pipelines.Provider) sleap.nn.data.pipelines.Pipeline [source]#
Create full training pipeline.
- Parameters
data_provider – A
Provider
that generates data examples, typically aLabelsReader
instance.- Returns
A
Pipeline
instance configured to produce all data keys required for training.
Notes
This does not remap keys to model outputs. Use
KeyMapper
to pull out keys with the appropriate format for the instantiatedtf.keras.Model
.
- make_viz_pipeline(data_provider: sleap.nn.data.pipelines.Provider, keras_model: keras.engine.training.Model) sleap.nn.data.pipelines.Pipeline [source]#
Create visualization pipeline.
- Parameters
data_provider – A
Provider
that generates data examples, typically aLabelsReader
instance.keras_model – A
tf.keras.Model
that can be used for inference.
- Returns
A
Pipeline
instance configured to fetch data and run inference to generate predictions useful for visualization during training.
- class sleap.nn.data.pipelines.Pipeline(providers: Any = NOTHING, transformers: Any = NOTHING)[source]#
Pipeline composed of providers and transformers.
- providers#
A single or a list of data providers.
- Type
List[sleap.nn.data.pipelines.Provider]
- transformers#
A single or a list of transformers.
- Type
List[sleap.nn.data.pipelines.Transformer]
- append(other: Union[sleap.nn.data.pipelines.Pipeline, sleap.nn.data.pipelines.Transformer, List[sleap.nn.data.pipelines.Transformer]])[source]#
Append one or more blocks to this pipeline instance.
- describe(return_description: bool = False) Optional[str] [source]#
Prints the keys in the examples generated by the pipeline.
- Parameters
return_description – If
True
, returns the string description instead of printing it.- Returns
String description if
return_description
isTrue
, otherwiseNone
.
- classmethod from_blocks(blocks: Union[sleap.nn.data.pipelines.Provider, sleap.nn.data.pipelines.Transformer, Sequence[Union[sleap.nn.data.pipelines.Provider, sleap.nn.data.pipelines.Transformer]]]) sleap.nn.data.pipelines.Pipeline [source]#
Create a pipeline from a sequence of providers and transformers.
- Parameters
blocks – List or tuple of providers and transformer instances.
- Returns
An instantiated pipeline with all blocks chained.
- classmethod from_pipelines(pipelines: Sequence[sleap.nn.data.pipelines.Pipeline]) sleap.nn.data.pipelines.Pipeline [source]#
Create a new pipeline instance by chaining together multiple pipelines.
- make_dataset() tensorflow.python.data.ops.dataset_ops.DatasetV2 [source]#
Create a dataset instance that generates examples from the pipeline.
- Returns
The instantiated
tf.data.Dataset
pipeline that generates examples with the keys in theoutput_keys
attribute.
- property output_keys: List[str]#
Return the keys in examples from a dataset generated from this pipeline.
- peek(n: int = 1) Union[Dict[str, tensorflow.python.framework.ops.Tensor], List[Dict[str, tensorflow.python.framework.ops.Tensor]]] [source]#
Build and return the first
n
examples from the pipeline.This function is useful for quickly inspecting the output of a pipeline.
- Parameters
n – Number of examples to get from the pipeline.
- Returns
A dictionary with tensors if
n = 1
, or a list of dictionaries ifn > 1
.
- class sleap.nn.data.pipelines.SingleInstanceConfmapsPipeline(data_config: sleap.nn.config.data.DataConfig, optimization_config: sleap.nn.config.optimization.OptimizationConfig, single_instance_confmap_head: sleap.nn.heads.SingleInstanceConfmapsHead, offsets_head: Optional[sleap.nn.heads.OffsetRefinementHead] = None)[source]#
Pipeline builder for single-instance confidence map models.
- data_config#
Data-related configuration.
- optimization_config#
Optimization-related configuration.
- single_instance_confmap_head#
Instantiated head describing the output confidence maps tensor.
- offsets_head#
Optional head describing the offset refinement maps.
- Type
Optional[sleap.nn.heads.OffsetRefinementHead]
- make_base_pipeline(data_provider: sleap.nn.data.pipelines.Provider) sleap.nn.data.pipelines.Pipeline [source]#
Create base pipeline with input data only.
- Parameters
data_provider – A
Provider
that generates data examples, typically aLabelsReader
instance.- Returns
A
Pipeline
instance configured to produce input examples.
- make_training_pipeline(data_provider: sleap.nn.data.pipelines.Provider) sleap.nn.data.pipelines.Pipeline [source]#
Create full training pipeline.
- Parameters
data_provider – A
Provider
that generates data examples, typically aLabelsReader
instance.- Returns
A
Pipeline
instance configured to produce all data keys required for training.
Notes
This does not remap keys to model outputs. Use
KeyMapper
to pull out keys with the appropriate format for the instantiatedtf.keras.Model
.
- make_viz_pipeline(data_provider: sleap.nn.data.pipelines.Provider, keras_model: keras.engine.training.Model) sleap.nn.data.pipelines.Pipeline [source]#
Create visualization pipeline.
- Parameters
data_provider – A
Provider
that generates data examples, typically aLabelsReader
instance.keras_model – A
tf.keras.Model
that can be used for inference.
- Returns
A
Pipeline
instance configured to fetch data and run inference to generate predictions useful for visualization during training.
- class sleap.nn.data.pipelines.TopDownMultiClassPipeline(data_config: sleap.nn.config.data.DataConfig, optimization_config: sleap.nn.config.optimization.OptimizationConfig, instance_confmap_head: sleap.nn.heads.CenteredInstanceConfmapsHead, class_vectors_head: sleap.nn.heads.ClassVectorsHead, offsets_head: Optional[sleap.nn.heads.OffsetRefinementHead] = None)[source]#
Pipeline builder for confidence maps and class maps models.
- data_config#
Data-related configuration.
- optimization_config#
Optimization-related configuration.
- confmaps_head#
Instantiated head describing the output confidence maps tensor.
- class_vectors_head#
Instantiated head describing the output class vectors tensor.
- offsets_head#
Optional head describing the offset refinement maps.
- Type
Optional[sleap.nn.heads.OffsetRefinementHead]
- make_base_pipeline(data_provider: sleap.nn.data.pipelines.Provider) sleap.nn.data.pipelines.Pipeline [source]#
Create base pipeline with input data only.
- Parameters
data_provider – A
Provider
that generates data examples, typically aLabelsReader
instance.- Returns
A
Pipeline
instance configured to produce input examples.
- make_training_pipeline(data_provider: sleap.nn.data.pipelines.Provider) sleap.nn.data.pipelines.Pipeline [source]#
Create full training pipeline.
- Parameters
data_provider – A
Provider
that generates data examples, typically aLabelsReader
instance.- Returns
A
Pipeline
instance configured to produce all data keys required for training.
Notes
This does not remap keys to model outputs. Use
KeyMapper
to pull out keys with the appropriate format for the instantiatedtf.keras.Model
.
- make_viz_pipeline(data_provider: sleap.nn.data.pipelines.Provider) sleap.nn.data.pipelines.Pipeline [source]#
Create visualization pipeline.
- Parameters
data_provider – A
Provider
that generates data examples, typically aLabelsReader
instance.- Returns
A
Pipeline
instance configured to fetch data and run inference to generate predictions useful for visualization during training.
- class sleap.nn.data.pipelines.TopdownConfmapsPipeline(data_config: sleap.nn.config.data.DataConfig, optimization_config: sleap.nn.config.optimization.OptimizationConfig, instance_confmap_head: sleap.nn.heads.CenteredInstanceConfmapsHead, offsets_head: Optional[sleap.nn.heads.OffsetRefinementHead] = None)[source]#
Pipeline builder for instance-centered confidence map models.
- data_config#
Data-related configuration.
- optimization_config#
Optimization-related configuration.
- instance_confmap_head#
Instantiated head describing the output centered confidence maps tensor.
- offsets_head#
Optional head describing the offset refinement maps.
- Type
Optional[sleap.nn.heads.OffsetRefinementHead]
- make_base_pipeline(data_provider: sleap.nn.data.pipelines.Provider) sleap.nn.data.pipelines.Pipeline [source]#
Create base pipeline with input data only.
- Parameters
data_provider – A
Provider
that generates data examples, typically aLabelsReader
instance.- Returns
A
Pipeline
instance configured to produce input examples.
- make_training_pipeline(data_provider: sleap.nn.data.pipelines.Provider) sleap.nn.data.pipelines.Pipeline [source]#
Create full training pipeline.
- Parameters
data_provider – A
Provider
that generates data examples, typically aLabelsReader
instance.- Returns
A
Pipeline
instance configured to produce all data keys required for training.
Notes
This does not remap keys to model outputs. Use
KeyMapper
to pull out keys with the appropriate format for the instantiatedtf.keras.Model
.
- make_viz_pipeline(data_provider: sleap.nn.data.pipelines.Provider) sleap.nn.data.pipelines.Pipeline [source]#
Create visualization pipeline.
- Parameters
data_provider – A
Provider
that generates data examples, typically aLabelsReader
instance.- Returns
A
Pipeline
instance configured to fetch data and for running inference to generate predictions useful for visualization during training.