sleap.nn.training#
Training functionality and high level APIs.
- class sleap.nn.training.BottomUpModelTrainer(data_readers: sleap.nn.training.DataReaders, model: sleap.nn.model.Model, config: sleap.nn.config.training_job.TrainingJobConfig, initial_config: Optional[sleap.nn.config.training_job.TrainingJobConfig] = None)[source]#
Trainer for models that output multi-instance confidence maps and PAFs.
- property has_offsets: bool#
Whether model is configured to output refinement offsets.
- property input_keys: List[str]#
Return example keys to be mapped to model inputs.
- property output_keys: List[str]#
Return example keys to be mapped to model outputs.
- class sleap.nn.training.BottomUpMultiClassModelTrainer(data_readers: sleap.nn.training.DataReaders, model: sleap.nn.model.Model, config: sleap.nn.config.training_job.TrainingJobConfig, initial_config: Optional[sleap.nn.config.training_job.TrainingJobConfig] = None)[source]#
Trainer for models that output multi-instance confidence maps and class maps.
- property has_offsets: bool#
Whether model is configured to output refinement offsets.
- property input_keys: List[str]#
Return example keys to be mapped to model inputs.
- property output_keys: List[str]#
Return example keys to be mapped to model outputs.
- class sleap.nn.training.CentroidConfmapsModelTrainer(data_readers: sleap.nn.training.DataReaders, model: sleap.nn.model.Model, config: sleap.nn.config.training_job.TrainingJobConfig, initial_config: Optional[sleap.nn.config.training_job.TrainingJobConfig] = None)[source]#
Trainer for models that output centroid confidence maps.
- property has_offsets: bool#
Whether model is configured to output refinement offsets.
- property input_keys: List[str]#
Return example keys to be mapped to model inputs.
- property output_keys: List[str]#
Return example keys to be mapped to model outputs.
- class sleap.nn.training.DataReaders(training_labels_reader: sleap.nn.data.providers.LabelsReader, validation_labels_reader: sleap.nn.data.providers.LabelsReader, test_labels_reader: Optional[sleap.nn.data.providers.LabelsReader] = None)[source]#
Container class for SLEAP labels that serve as training data sources.
- training_labels_reader#
LabelsReader pipeline provider for a training data from a
Labels
instance.
- validation_labels_reader#
LabelsReader pipeline provider for a validation data from a
Labels
instance.
- test_labels_reader#
LabelsReader pipeline provider for a test set data from a
Labels
instance. This is not necessary for training.- Type
Optional[sleap.nn.data.providers.LabelsReader]
- classmethod from_config(labels_config: sleap.nn.config.data.LabelsConfig, training: Union[str, sleap.io.dataset.Labels], validation: Union[str, sleap.io.dataset.Labels, float], test: Optional[Union[str, sleap.io.dataset.Labels]] = None, video_search_paths: Optional[List[str]] = None, update_config: bool = False, with_track_only: bool = False) sleap.nn.training.DataReaders [source]#
Create data readers from a (possibly incomplete) configuration.
- classmethod from_labels(training: Union[str, sleap.io.dataset.Labels], validation: Union[str, sleap.io.dataset.Labels, float], test: Optional[Union[str, sleap.io.dataset.Labels]] = None, video_search_paths: Optional[List[str]] = None, labels_config: Optional[sleap.nn.config.data.LabelsConfig] = None, update_config: bool = False, with_track_only: bool = False) sleap.nn.training.DataReaders [source]#
Create data readers from
Labels
datasets as data providers.
- property test_labels: sleap.io.dataset.Labels#
Return the
Labels
underlying the test data reader.
- property training_labels: sleap.io.dataset.Labels#
Return the
Labels
underlying the training data reader.
- property validation_labels: sleap.io.dataset.Labels#
Return the
Labels
underlying the validation data reader.
- class sleap.nn.training.SingleInstanceModelTrainer(data_readers: sleap.nn.training.DataReaders, model: sleap.nn.model.Model, config: sleap.nn.config.training_job.TrainingJobConfig, initial_config: Optional[sleap.nn.config.training_job.TrainingJobConfig] = None)[source]#
Trainer for models that output single-instance confidence maps.
- property has_offsets: bool#
Whether model is configured to output refinement offsets.
- property input_keys: List[str]#
Return example keys to be mapped to model inputs.
- property output_keys: List[str]#
Return example keys to be mapped to model outputs.
- class sleap.nn.training.TopDownMultiClassModelTrainer(data_readers: sleap.nn.training.DataReaders, model: sleap.nn.model.Model, config: sleap.nn.config.training_job.TrainingJobConfig, initial_config: Optional[sleap.nn.config.training_job.TrainingJobConfig] = None)[source]#
Trainer for models that output multi-instance confidence maps and class maps.
- property has_offsets: bool#
Whether model is configured to output refinement offsets.
- property input_keys: List[str]#
Return example keys to be mapped to model inputs.
- property output_keys: List[str]#
Return example keys to be mapped to model outputs.
- class sleap.nn.training.TopdownConfmapsModelTrainer(data_readers: sleap.nn.training.DataReaders, model: sleap.nn.model.Model, config: sleap.nn.config.training_job.TrainingJobConfig, initial_config: Optional[sleap.nn.config.training_job.TrainingJobConfig] = None)[source]#
Trainer for models that output instance centered confidence maps.
- property has_offsets: bool#
Whether model is configured to output refinement offsets.
- property input_keys: List[str]#
Return example keys to be mapped to model inputs.
- property output_keys: List[str]#
Return example keys to be mapped to model outputs.
- class sleap.nn.training.Trainer(data_readers: sleap.nn.training.DataReaders, model: sleap.nn.model.Model, config: sleap.nn.config.training_job.TrainingJobConfig, initial_config: Optional[sleap.nn.config.training_job.TrainingJobConfig] = None)[source]#
Base trainer class that provides general model training functionality.
This class is intended to be instantiated using the
from_config()
class method, which will return the appropriate subclass based on the input configuration.This class should not be used directly. It is intended to be subclassed by a model output type-specific trainer that provides more specific functionality.
- data_readers#
A
DataReaders
instance that contains training data providers.
- model#
A
Model
instance describing the SLEAP model to train.- Type
- config#
A
TrainingJobConfig
that describes the training parameters.
- initial_config#
This attribute will contain a copy of the input configuration before any attributes are updated in
config
.- Type
- pipeline_builder#
A model output type-specific data pipeline builder to create pipelines that generate data used for training. This must be specified in subclasses.
- Type
sleap.nn.training.PipelineBuilder
- training_pipeline#
The data pipeline that generates examples from the training set for optimization.
- validation_pipeline#
The data pipeline that generates examples from the validation set for optimization.
- training_viz_pipeline#
The data pipeline that generates examples from the training set for visualization.
- validation_viz_pipeline#
The data pipeline that generates examples from the validation set for visualization.
- optimization_callbacks#
Keras callbacks related to optimization.
- Type
List[keras.callbacks.Callback]
- output_callbacks#
Keras callbacks related to outputs.
- Type
List[keras.callbacks.Callback]
- visualization_callbacks#
Keras callbacks related to visualization.
- Type
List[keras.callbacks.Callback]
- run_path#
The path to the run folder that will contain training results, if any.
- Type
Optional[str]
- property callbacks: List[keras.callbacks.Callback]#
Return all callbacks currently configured.
- classmethod from_config(config: sleap.nn.config.training_job.TrainingJobConfig, training_labels: Optional[Union[str, sleap.io.dataset.Labels]] = None, validation_labels: Optional[Union[str, sleap.io.dataset.Labels, float]] = None, test_labels: Optional[Union[str, sleap.io.dataset.Labels]] = None, video_search_paths: Optional[List[str]] = None) sleap.nn.training.Trainer [source]#
Initialize the trainer from a training job configuration.
- Parameters
config – A
TrainingJobConfig
instance.training_labels – Training labels to use instead of the ones in the config, if any. If a path is specified, it will overwrite the one in the config.
validation_labels – Validation labels to use instead of the ones in the config, if any. If a path is specified, it will overwrite the one in the config.
test_labels – Teset labels to use instead of the ones in the config, if any. If a path is specified, it will overwrite the one in the config.
- abstract property input_keys#
Implement in subclasses.
- property keras_model: keras.engine.training.Model#
Alias for
self.model.keras_model
.
- abstract property output_keys#
Implement in subclasses.
- sleap.nn.training.create_trainer_using_cli(args: Optional[List] = None)[source]#
Create CLI for training.
- sleap.nn.training.sanitize_scope_name(name: str) str [source]#
Sanitizes string which will be used as TensorFlow scope name.
- sleap.nn.training.setup_checkpointing(config: sleap.nn.config.outputs.CheckpointingConfig, run_path: str) List[keras.callbacks.Callback] [source]#
Set up model checkpointing callbacks from config.
- sleap.nn.training.setup_losses(config: sleap.nn.config.optimization.OptimizationConfig) Callable[[tensorflow.python.framework.ops.Tensor, tensorflow.python.framework.ops.Tensor], tensorflow.python.framework.ops.Tensor] [source]#
Set up model loss function from config.
- sleap.nn.training.setup_metrics(config: sleap.nn.config.optimization.OptimizationConfig, part_names: Optional[List[str]] = None) List[Union[keras.losses.Loss, keras.metrics.Metric]] [source]#
Set up training metrics from config.
- sleap.nn.training.setup_new_run_folder(config: sleap.nn.config.outputs.OutputsConfig, base_run_name: Optional[str] = None) str [source]#
Create a new run folder from config.
- sleap.nn.training.setup_optimization_callbacks(config: sleap.nn.config.optimization.OptimizationConfig) List[keras.callbacks.Callback] [source]#
Set up optimization callbacks from config.
- sleap.nn.training.setup_optimizer(config: sleap.nn.config.optimization.OptimizationConfig) keras.optimizer_v2.optimizer_v2.OptimizerV2 [source]#
Set up model optimizer from config.
- sleap.nn.training.setup_output_callbacks(config: sleap.nn.config.outputs.OutputsConfig, run_path: Optional[str] = None) List[keras.callbacks.Callback] [source]#
Set up training outputs callbacks from config.
- sleap.nn.training.setup_tensorboard(config: sleap.nn.config.outputs.TensorBoardConfig, run_path: str) List[keras.callbacks.Callback] [source]#
Set up TensorBoard callbacks from config.
- sleap.nn.training.setup_visualization(config: sleap.nn.config.outputs.OutputsConfig, run_path: str, viz_fn: Callable[[], matplotlib.figure.Figure], name: str) List[keras.callbacks.Callback] [source]#
Set up visualization callbacks from config.
- sleap.nn.training.setup_zmq_callbacks(zmq_config: sleap.nn.config.outputs.ZMQConfig) List[keras.callbacks.Callback] [source]#
Set up ZeroMQ callbacks from config.