sleap.nn.config.training_job#

Serializable configuration classes for specifying all training job parameters.

These configuration classes are intended to specify all the parameters required to run a training job or perform inference from a serialized one.

They are explicitly not intended to implement any of the underlying functionality that they parametrize. This serves two purposes:

  1. Parameter specification through simple attributes. These can be read/edited by a

    human, as well as easily be serialized/deserialized to/from simple dictionaries and JSON.

  2. Decoupling from the implementation. This makes it easier to design functional

    modules with attributes/parameters that contain objects that may not be easily serializable or may implement additional logic that relies on runtime information or other parameters.

In general, classes that implement the actual functionality related to these configuration classes should provide a classmethod for instantiation from the configuration class instances. This makes it easier to implement other logic not related to the high level parameters at creation time.

Conveniently, this format also provides a single location where all user-facing parameters are aggregated and documented for end users (as opposed to developers).

class sleap.nn.config.training_job.TrainingJobConfig(data: sleap.nn.config.data.DataConfig = NOTHING, model: sleap.nn.config.model.ModelConfig = NOTHING, optimization: sleap.nn.config.optimization.OptimizationConfig = NOTHING, outputs: sleap.nn.config.outputs.OutputsConfig = NOTHING, name: Optional[str] = '', description: Optional[str] = '', sleap_version: Optional[str] = '1.3.3', filename: Optional[str] = '')[source]#

Configuration of a training job.

data#

Configuration options related to the training data.

Type

sleap.nn.config.data.DataConfig

model#

Configuration options related to the model architecture.

Type

sleap.nn.config.model.ModelConfig

optimization#

Configuration options related to the training.

Type

sleap.nn.config.optimization.OptimizationConfig

outputs#

Configuration options related to outputs during training.

Type

sleap.nn.config.outputs.OutputsConfig

name#

Optional name for this configuration profile.

Type

Optional[str]

description#

Optional description of the configuration.

Type

Optional[str]

sleap_version#

Version of SLEAP that generated this configuration.

Type

Optional[str]

filename#

Path to this config file if it was loaded from disk.

Type

Optional[str]

classmethod from_json(json_data: str) sleap.nn.config.training_job.TrainingJobConfig[source]#

Create training job configuration from JSON text data.

Parameters

json_data – JSON-formatted string that specifies the configurations.

Returns

A TrainingJobConfig instance parsed from the JSON text.

classmethod from_json_dicts(json_data_dicts: Dict[str, Any]) sleap.nn.config.training_job.TrainingJobConfig[source]#

Create training job configuration from dictionaries decoded from JSON.

Parameters

json_data_dicts – Dictionaries that specify the configurations. These are typically generated by structuring raw JSON formatted text.

Returns

A TrainingJobConfig instance parsed from the JSON dicts.

classmethod load_json(filename: str, load_training_config: bool = True) sleap.nn.config.training_job.TrainingJobConfig[source]#

Load a training job configuration from a file.

Parameters
  • filename – Path to a training job configuration JSON file or a directory containing "training_job.json".

  • load_training_config – If True (the default), prefer training_job.json over initial_config.json if it is present in the same folder.

Returns

A TrainingJobConfig instance parsed from the file.

save_json(filename: str)[source]#

Save the configuration to a JSON file.

Parameters

filename – Path to save the training job file to.

to_json() str[source]#

Serialize the configuration into JSON-encoded string format.

Returns

The JSON encoded string representation of the configuration.

sleap.nn.config.training_job.load_config(filename: str, load_training_config: bool = True) sleap.nn.config.training_job.TrainingJobConfig[source]#

Load a training job configuration for a model run.

Parameters
  • filename – Path to a JSON file or directory containing training_job.json.

  • load_training_config – If True (the default), prefer training_job.json over initial_config.json if it is present in the same folder.

Returns

The parsed TrainingJobConfig.