Skip to content

Losses

Source

Losses module.

denoisplit_loss(model_outputs, targets, config, gaussian_likelihood=None, noise_model_likelihood=None)

Loss function for DenoiSplit.

Parameters:

  • model_outputs (tuple[Tensor, dict[str, Any]]) –

    Tuple containing the model predictions (shape is (B, target_ch, [Z], Y, X)) and the top-down layer data (e.g., sampled latents, KL-loss values, etc.).

  • targets (Tensor) –

    The target image used to compute the reconstruction loss. Shape is (B, target_ch, [Z], Y, X).

  • config (LVAELossConfig) –

    The config for loss function containing all loss hyperparameters.

  • gaussian_likelihood (GaussianLikelihood, default: None ) –

    The Gaussian likelihood object.

  • noise_model_likelihood (NoiseModelLikelihood, default: None ) –

    The noise model likelihood object.

Returns:

  • output ( Optional[dict[str, Tensor]] ) –

    A dictionary containing the overall loss ["loss"], the reconstruction loss ["reconstruction_loss"], and the KL divergence loss ["kl_loss"].

denoisplit_musplit_loss(model_outputs, targets, config, gaussian_likelihood, noise_model_likelihood)

Loss function for DenoiSplit.

Parameters:

  • model_outputs (tuple[Tensor, dict[str, Any]]) –

    Tuple containing the model predictions (shape is (B, target_ch, [Z], Y, X)) and the top-down layer data (e.g., sampled latents, KL-loss values, etc.).

  • targets (Tensor) –

    The target image used to compute the reconstruction loss. Shape is (B, target_ch, [Z], Y, X).

  • config (LVAELossConfig) –

    The config for loss function containing all loss hyperparameters.

  • gaussian_likelihood (GaussianLikelihood) –

    The Gaussian likelihood object.

  • noise_model_likelihood (NoiseModelLikelihood) –

    The noise model likelihood object.

Returns:

  • output ( Optional[dict[str, Tensor]] ) –

    A dictionary containing the overall loss ["loss"], the reconstruction loss ["reconstruction_loss"], and the KL divergence loss ["kl_loss"].

hdn_loss(model_outputs, targets, config, gaussian_likelihood, noise_model_likelihood)

Loss function for HDN.

Parameters:

  • model_outputs (tuple[Tensor, dict[str, Any]]) –

    Tuple containing the model predictions (shape is (B, target_ch, [Z], Y, X)) and the top-down layer data (e.g., sampled latents, KL-loss values, etc.).

  • targets (Tensor) –

    The target image used to compute the reconstruction loss. In this case we use the input patch itself as target. Shape is (B, target_ch, [Z], Y, X).

  • config (LVAELossConfig) –

    The config for loss function containing all loss hyperparameters.

  • gaussian_likelihood (GaussianLikelihood) –

    The Gaussian likelihood object.

  • noise_model_likelihood (NoiseModelLikelihood) –

    The noise model likelihood object.

Returns:

  • output ( Optional[dict[str, Tensor]] ) –

    A dictionary containing the overall loss ["loss"], the reconstruction loss ["reconstruction_loss"], and the KL divergence loss ["kl_loss"].

musplit_loss(model_outputs, targets, config, gaussian_likelihood, noise_model_likelihood=None)

Loss function for muSplit.

Parameters:

  • model_outputs (tuple[Tensor, dict[str, Any]]) –

    Tuple containing the model predictions (shape is (B, target_ch, [Z], Y, X)) and the top-down layer data (e.g., sampled latents, KL-loss values, etc.).

  • targets (Tensor) –

    The target image used to compute the reconstruction loss. Shape is (B, target_ch, [Z], Y, X).

  • config (LVAELossConfig) –

    The config for loss function (e.g., KL hyperparameters, likelihood module, noise model, etc.).

  • gaussian_likelihood (GaussianLikelihood) –

    The Gaussian likelihood object.

  • noise_model_likelihood (Optional[NoiseModelLikelihood], default: None ) –

    The noise model likelihood object. Not used here.

Returns:

  • output ( Optional[dict[str, Tensor]] ) –

    A dictionary containing the overall loss ["loss"], the reconstruction loss ["reconstruction_loss"], and the KL divergence loss ["kl_loss"].

n2v_loss(manipulated_batch, original_batch, masks, *args)

N2V Loss function described in A Krull et al 2018.

Parameters:

  • manipulated_batch (Tensor) –

    Batch after manipulation function applied.

  • original_batch (Tensor) –

    Original images.

  • masks (Tensor) –

    Coordinates of changed pixels.

  • *args (Any, default: () ) –

    Additional arguments.

Returns:

  • Tensor

    Loss value.

pn2v_loss(samples, labels, masks, noise_model)

Probabilistic N2V loss function described in A Krull et al., CVF (2019).

Parameters:

  • samples (Tensor) –

    Predicted pixel values from the network.

  • labels (Tensor) –

    Original pixel values.

  • masks (Tensor) –

    Coordinates of manipulated pixels.

  • noise_model (GaussianMixtureNoiseModel) –

    Noise model for computing likelihood.

Returns:

  • Tensor

    Loss value.