Skip to content

Configuration

Source

CAREamics configuration compatible with the NG Dataset.

Configuration

Bases: BaseModel, Generic[AlgorithmConfig]

CAREamics configuration.

The configuration defines all parameters used to build and train a CAREamics model. These parameters are validated to ensure that they are compatible with each other.

It contains three sub-configurations:

  • AlgorithmModel: configuration for the algorithm training, which includes the architecture, loss function, optimizer, and other hyperparameters.
  • DataModel: configuration for the dataloader, which includes the type of data, transformations, mean/std and other parameters.
  • TrainingModel: configuration for the training, which includes the number of epochs or the callbacks.

Attributes:

  • experiment_name (str) –

    Name of the experiment, used when saving logs and checkpoints.

  • algorithm (AlgorithmModel) –

    Algorithm configuration.

  • data (DataModel) –

    Data configuration.

  • training (TrainingModel) –

    Training configuration.

Raises:

  • ValueError

    Configuration parameter type validation errors.

  • ValueError

    If the experiment name contains invalid characters or is empty.

  • ValueError

    If the algorithm is 3D but there is not "Z" in the data axes, or 2D algorithm with "Z" in data axes.

  • ValueError

    Algorithm, data or training validation errors.

algorithm_config instance-attribute

Algorithm configuration, holding all parameters required to configure the model.

data_config instance-attribute

Data configuration, holding all parameters required to configure the training data loader.

experiment_name instance-attribute

Name of the experiment, used to name logs and checkpoints.

training_config = Field(default_factory=default_training_factory) class-attribute instance-attribute

Training configuration, holding all parameters required to configure the training process.

version = '0.2.0' class-attribute instance-attribute

CAREamics configuration version.

__str__()

Pretty string reprensenting the configuration.

Returns:

  • str

    Pretty string.

get_algorithm_citations()

Return a list of citation entries of the current algorithm.

This is used to generate the model description for the BioImage Model Zoo.

Returns:

  • List[CiteEntry]

    List of citation entries.

get_algorithm_description()

Return a description of the algorithm.

This method is used to generate the README of the BioImage Model Zoo export.

Returns:

  • str

    Description of the algorithm.

get_algorithm_friendly_name()

Get the algorithm name.

Returns:

  • str

    Algorithm name.

get_algorithm_keywords()

Get algorithm keywords.

Returns:

get_algorithm_references()

Get the algorithm references.

This is used to generate the README of the BioImage Model Zoo export.

Returns:

  • str

    Algorithm references.

get_safe_experiment_name()

Return the experiment name safe for use in paths and filenames.

Spaces are replaced with underscores to avoid issues with folder creation and checkpoint naming.

Returns:

  • str

    Experiment name with spaces replaced with underscores.

is_supervised()

Return whether the algorithm is supervised.

This is true for CARE and N2N, and false for N2V. This is used to determine whether a target is required for training.

Returns:

  • bool

    True if the algorithm is supervised, False otherwise.

model_dump(**kwargs)

Override model_dump method in order to set default values.

As opposed to the parent model_dump method, this method sets exclude none by default.

Parameters:

  • **kwargs (Any, default: {} ) –

    Additional arguments to pass to the parent model_dump method.

Returns:

  • dict

    Dictionary containing the model parameters.

no_symbol(name) classmethod

Validate experiment name.

A valid experiment name is a non-empty string that only contains letters, numbers, underscores, dashes and spaces.

Parameters:

  • name (str) –

    Name to validate.

Returns:

  • str

    Validated name.

Raises:

  • ValueError

    If the name is empty or contains invalid characters.

set_3D(is_3D, axes, patch_size)

Set 3D flag and axes.

Parameters:

  • is_3D (bool) –

    Whether the algorithm is 3D or not.

  • axes (str) –

    Axes of the data.

  • patch_size (list[int]) –

    Patch size.

validate_3D()

Validate algorithm dimensions to match data dimensions.

Returns:

  • Self

    Validated configuration.

validate_channels_against_inputs()

Validate that the number of channels in the data is compatible with the model.

Returns:

  • Self

    Validated configuration.

validate_norm_against_channels()

Validate that normalization is compatible with the model in/out channels.

Returns:

  • Self

    Validated configuration.

validate_patch_against_model()

Validate that the patch size is compatible with the model constraints.

This is done by checking that the patch size is compatible with the model constraints.

Returns:

  • Self

    Validated configuration.

warn_batch_norm()

Warn if batch normalization is used with small batch size.

Returns:

  • Self

    Validated configuration.