PairwiseProjectionsLossο
- class lightning_pose.losses.losses.PairwiseProjectionsLoss[source]ο
Bases:
LossPenalize projections from each pair of cameras into 3D world space.
Attributes Summary
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_3dorkeypoints_pred_3disNone.
- 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)ο