PairwiseProjectionsLoss

class lightning_pose.losses.losses.PairwiseProjectionsLoss[source]

Bases: Loss

Penalize projections from each pair of cameras into 3D world space.

Attributes Summary

loss_name

Methods Summary

__call__(keypoints_targ_3d,Β keypoints_pred_3d)

Compute the pairwise projections loss.

compute_loss(targets,Β predictions)

Compute L2 distance between 3D target and per-camera-pair predicted 3D keypoints.

remove_nans(loss)

Select only valid (non-NaN) loss entries.

Attributes Documentation

loss_name: str = 'supervised_pairwise_projections'

Methods Documentation

__call__(keypoints_targ_3d: Float[Tensor, 'batch num_keypoints 3'], keypoints_pred_3d: Float[Tensor, 'batch cam_pairs num_keypoints 3'], stage: Literal['train', 'val', 'test'] | None = None, **kwargs: Any) tuple[Float[Tensor, ''], list[dict]][source]

Compute the pairwise projections loss.

Parameters:
  • keypoints_targ_3d – ground-truth 3D keypoints of shape (batch, num_keypoints, 3).

  • keypoints_pred_3d – predicted 3D keypoints per camera pair, shape (batch, cam_pairs, num_keypoints, 3).

  • stage – training stage for logging.

  • **kwargs – ignored extra keyword arguments.

Returns:

Tuple of scalar loss and list of logging dicts.

Raises:

ValueError – if either keypoints_targ_3d or keypoints_pred_3d is None.

compute_loss(targets: Float[Tensor, 'batch num_keypoints 3'], predictions: Float[Tensor, 'batch cam_pairs num_keypoints 3']) Float[Tensor, 'batch cam_pairs num_keypoints'][source]

Compute L2 distance between 3D target and per-camera-pair predicted 3D keypoints.

Parameters:
  • targets – ground-truth 3D keypoints of shape (batch, num_keypoints, 3).

  • predictions – predicted 3D points from pairwise triangulation, shape (batch, cam_pairs, num_keypoints, 3).

Returns:

Per-pair per-keypoint L2 distances; NaN where targets or predictions are missing.

remove_nans(loss: Float[Tensor, 'batch cam_pairs num_keypoints']) Float[Tensor, 'valid_losses'][source]

Select only valid (non-NaN) loss entries.

Parameters:

loss – per-pair per-keypoint loss tensor; NaN indicates a missing keypoint.

Returns:

Flat tensor of valid loss values, or a zero scalar if none are valid.

__init__(log_weight: float = 0.0, **kwargs: Any) None[source]

Initialize PairwiseProjectionsLoss.

Parameters:

log_weight – final weight in front of the loss term in the objective function is computed as 1.0 / (2.0 * exp(log_weight)).

__new__(**kwargs)