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[] = None)[source]

SLEAP model that describes an architecture and output types.


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


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


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.

  • config – The configurations as a ModelConfig instance.

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


An instance of Model built with the specified configurations.

make_model(input_shape: Tuple[int, int, int]) →[source]

Create a trainable model from the configuration.


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


An instantiated tf.keras.Model.

property maximum_stride

Return the maximum stride of the model backbone.