Skip to content

n2n_algorithm_model

N2N Algorithm configuration.

N2NAlgorithm #

Bases: UNetBasedAlgorithm

Noise2Noise Algorithm configuration.

Source code in src/careamics/config/algorithms/n2n_algorithm_model.py
class N2NAlgorithm(UNetBasedAlgorithm):
    """Noise2Noise Algorithm configuration."""

    algorithm: Literal["n2n"] = "n2n"
    """N2N Algorithm name."""

    loss: Literal["mae", "mse"] = "mae"
    """N2N-compatible loss function."""

    model: Annotated[
        UNetModel,
        AfterValidator(model_without_n2v2),
        AfterValidator(model_without_final_activation),
    ]
    """UNet without a final activation function and without the `n2v2` modifications."""

    def get_algorithm_friendly_name(self) -> str:
        """
        Get the algorithm friendly name.

        Returns
        -------
        str
            Friendly name of the algorithm.
        """
        return N2N

    def get_algorithm_keywords(self) -> list[str]:
        """
        Get algorithm keywords.

        Returns
        -------
        list[str]
            List of keywords.
        """
        return [
            "restoration",
            "UNet",
            "3D" if self.model.is_3D() else "2D",
            "CAREamics",
            "pytorch",
            N2N,
        ]

    def get_algorithm_references(self) -> str:
        """
        Get the algorithm references.

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

        Returns
        -------
        str
            Algorithm references.
        """
        return N2N_REF.text + " doi: " + N2N_REF.doi

    def get_algorithm_citations(self) -> list[CiteEntry]:
        """
        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.
        """
        return [N2N_REF]

    def get_algorithm_description(self) -> str:
        """
        Get the algorithm description.

        Returns
        -------
        str
            Algorithm description.
        """
        return N2N_DESCRIPTION

algorithm = 'n2n' class-attribute instance-attribute #

N2N Algorithm name.

loss = 'mae' class-attribute instance-attribute #

N2N-compatible loss function.

model instance-attribute #

UNet without a final activation function and without the n2v2 modifications.

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:

Type Description
List[CiteEntry]

List of citation entries.

Source code in src/careamics/config/algorithms/n2n_algorithm_model.py
def get_algorithm_citations(self) -> list[CiteEntry]:
    """
    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.
    """
    return [N2N_REF]

get_algorithm_description() #

Get the algorithm description.

Returns:

Type Description
str

Algorithm description.

Source code in src/careamics/config/algorithms/n2n_algorithm_model.py
def get_algorithm_description(self) -> str:
    """
    Get the algorithm description.

    Returns
    -------
    str
        Algorithm description.
    """
    return N2N_DESCRIPTION

get_algorithm_friendly_name() #

Get the algorithm friendly name.

Returns:

Type Description
str

Friendly name of the algorithm.

Source code in src/careamics/config/algorithms/n2n_algorithm_model.py
def get_algorithm_friendly_name(self) -> str:
    """
    Get the algorithm friendly name.

    Returns
    -------
    str
        Friendly name of the algorithm.
    """
    return N2N

get_algorithm_keywords() #

Get algorithm keywords.

Returns:

Type Description
list[str]

List of keywords.

Source code in src/careamics/config/algorithms/n2n_algorithm_model.py
def get_algorithm_keywords(self) -> list[str]:
    """
    Get algorithm keywords.

    Returns
    -------
    list[str]
        List of keywords.
    """
    return [
        "restoration",
        "UNet",
        "3D" if self.model.is_3D() else "2D",
        "CAREamics",
        "pytorch",
        N2N,
    ]

get_algorithm_references() #

Get the algorithm references.

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

Returns:

Type Description
str

Algorithm references.

Source code in src/careamics/config/algorithms/n2n_algorithm_model.py
def get_algorithm_references(self) -> str:
    """
    Get the algorithm references.

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

    Returns
    -------
    str
        Algorithm references.
    """
    return N2N_REF.text + " doi: " + N2N_REF.doi