Skip to content

model_validators

Architecture model validators.

model_matching_in_out_channels(model) #

Validate that the UNet model has the same number of channel inputs and outputs.

Parameters:

Name Type Description Default
model UNetModel

Model to validate.

required

Returns:

Type Description
UNetModel

Validated model.

Raises:

Type Description
ValueError

If the model has different number of input and output channels.

Source code in src/careamics/config/validators/model_validators.py
def model_matching_in_out_channels(model: UNetModel) -> UNetModel:
    """Validate that the UNet model has the same number of channel inputs and outputs.

    Parameters
    ----------
    model : UNetModel
        Model to validate.

    Returns
    -------
    UNetModel
        Validated model.

    Raises
    ------
    ValueError
        If the model has different number of input and output channels.
    """
    if model.num_classes != model.in_channels:
        raise ValueError(
            "The algorithm requires the same number of input and output channels. "
            "Make sure that `in_channels` and `num_classes` are equal."
        )

    return model

model_without_final_activation(model) #

Validate that the UNet model does not have the final_activation.

Parameters:

Name Type Description Default
model UNetModel

Model to validate.

required

Returns:

Type Description
UNetModel

The validated model.

Raises:

Type Description
ValueError

If the model has the final_activation attribute set.

Source code in src/careamics/config/validators/model_validators.py
def model_without_final_activation(model: UNetModel) -> UNetModel:
    """Validate that the UNet model does not have the final_activation.

    Parameters
    ----------
    model : UNetModel
        Model to validate.

    Returns
    -------
    UNetModel
        The validated model.

    Raises
    ------
    ValueError
        If the model has the final_activation attribute set.
    """
    if model.final_activation != "None":
        raise ValueError(
            "The algorithm does not support a `final_activation` in the model. "
            'Set it to `"None"`.'
        )

    return model

model_without_n2v2(model) #

Validate that the Unet model does not have the n2v2 attribute.

Parameters:

Name Type Description Default
model UNetModel

Model to validate.

required

Returns:

Type Description
UNetModel

The validated model.

Raises:

Type Description
ValueError

If the model has the n2v2 attribute set to True.

Source code in src/careamics/config/validators/model_validators.py
def model_without_n2v2(model: UNetModel) -> UNetModel:
    """Validate that the Unet model does not have the n2v2 attribute.

    Parameters
    ----------
    model : UNetModel
        Model to validate.

    Returns
    -------
    UNetModel
        The validated model.

    Raises
    ------
    ValueError
        If the model has the `n2v2` attribute set to `True`.
    """
    if model.n2v2:
        raise ValueError(
            "The algorithm does not support the `n2v2` attribute in the model. "
            "Set it to `False`."
        )

    return model