sleap.nn.model

This module defines the main SLEAP model class for defining a trainable model.

This is a higher level wrapper around tf.keras.Model that holds all the configuration parameters required to construct the actual model. This allows for easy querying of the model configuration without actually instantiating the model itself.

class sleap.nn.model.Model(backbone: Architecture, heads, keras_model: Optional[tensorflow.python.keras.engine.training.Model] = None)[source]

SLEAP model that describes an architecture and output types.

backbone

An Architecture class that provides methods for building a tf.keras.Model given an input.

heads

List of `Head`s that define the outputs of the network.

keras_model

The current tf.keras.Model instance if one has been created.

classmethod from_config(config: sleap.nn.config.model.ModelConfig, skeleton: Optional[sleap.skeleton.Skeleton] = None, update_config: bool = False)sleap.nn.model.Model[source]

Create a SLEAP model from configurations.

Parameters
  • config – The configurations as a ModelConfig instance.

  • skeleton – A sleap.Skeleton to use if not provided in the config.

Returns

An instance of Model built with the specified configurations.

make_model(input_shape: Tuple[int, int, int]) → tensorflow.python.keras.engine.training.Model[source]

Create a trainable model from the configuration.

Parameters

input_shape – Tuple of (height, width, channels) specifying the shape of the inputs before preprocessing.

Returns

An instantiated tf.keras.Model.

property maximum_stride

Return the maximum stride of the model backbone.