Metrics (sphero_vem.metrics)#

Image similarity loss functions and dispatcher.

This module contains losses and metrics used throughout the library

sphero_vem.metrics.ncc_loss(img1, img2, eps=1e-06)[source]#

Normalized cross-correlation loss between two image tensors.

Parameters:
  • img1 (torch.Tensor) – First input image tensor of shape (N, C, H, W).

  • img2 (torch.Tensor) – Second input image tensor. Must have the same shape as img1.

  • eps (float, optional) – Small constant added to the denominator for numerical stability. Default is 1e-6.

Returns:

Scalar NCC loss in [0, 2]; 0 for perfectly correlated images.

Return type:

torch.Tensor

class sphero_vem.metrics.LossDispatcher(loss_name)[source]#

Bases: object

Factory that resolves a loss function by name and forwards calls to it.

Available loss names: "mse", "mae", "ncc", "ssim".

Parameters:

loss_name (str) – Name of the loss function to use. Case-sensitive.

Raises:

ValueError – If loss_name is not in the registry.