sleap.nn.training#
Training functionality and high level APIs.
- class sleap.nn.training.BottomUpModelTrainer(data_readers: DataReaders, model: Model, config: TrainingJobConfig, initial_config: Optional[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: DataReaders, model: Model, config: TrainingJobConfig, initial_config: Optional[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: DataReaders, model: Model, config: TrainingJobConfig, initial_config: Optional[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: LabelsReader, validation_labels_reader: LabelsReader, test_labels_reader: Optional[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: LabelsConfig, training: Union[str, Labels], validation: Union[str, Labels, float], test: Optional[Union[str, Labels]] = None, video_search_paths: Optional[List[str]] = None, update_config: bool = False, with_track_only: bool = False) DataReaders [source]#
Create data readers from a (possibly incomplete) configuration.
- classmethod from_labels(training: Union[str, Labels], validation: Union[str, Labels, float], test: Optional[Union[str, Labels]] = None, video_search_paths: Optional[List[str]] = None, labels_config: Optional[LabelsConfig] = None, update_config: bool = False, with_track_only: bool = False) DataReaders [source]#
Create data readers from
Labels
datasets as data providers.
- class sleap.nn.training.SingleInstanceModelTrainer(data_readers: DataReaders, model: Model, config: TrainingJobConfig, initial_config: Optional[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: DataReaders, model: Model, config: TrainingJobConfig, initial_config: Optional[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: DataReaders, model: Model, config: TrainingJobConfig, initial_config: Optional[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: DataReaders, model: Model, config: TrainingJobConfig, initial_config: Optional[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[Callback]#
Return all callbacks currently configured.
- classmethod from_config(config: TrainingJobConfig, training_labels: Optional[Union[str, Labels]] = None, validation_labels: Optional[Union[str, Labels, float]] = None, test_labels: Optional[Union[str, Labels]] = None, video_search_paths: Optional[List[str]] = None) 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: 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: CheckpointingConfig, run_path: str) List[Callback] [source]#
Set up model checkpointing callbacks from config.
- sleap.nn.training.setup_losses(config: OptimizationConfig) Callable[[Tensor, Tensor], Tensor] [source]#
Set up model loss function from config.
- sleap.nn.training.setup_metrics(config: OptimizationConfig, part_names: Optional[List[str]] = None) List[Union[Loss, Metric]] [source]#
Set up training metrics from config.
- sleap.nn.training.setup_new_run_folder(config: OutputsConfig, base_run_name: Optional[str] = None) str [source]#
Create a new run folder from config.
- sleap.nn.training.setup_optimization_callbacks(config: OptimizationConfig) List[Callback] [source]#
Set up optimization callbacks from config.
- sleap.nn.training.setup_optimizer(config: OptimizationConfig) OptimizerV2 [source]#
Set up model optimizer from config.
- sleap.nn.training.setup_output_callbacks(config: OutputsConfig, run_path: Optional[str] = None) List[Callback] [source]#
Set up training outputs callbacks from config.
- sleap.nn.training.setup_tensorboard(config: TensorBoardConfig, run_path: str) List[Callback] [source]#
Set up TensorBoard callbacks from config.
- sleap.nn.training.setup_visualization(config: OutputsConfig, run_path: str, viz_fn: Callable[[], Figure], name: str) List[Callback] [source]#
Set up visualization callbacks from config.