PCALossο
- class lightning_pose.losses.losses.PCALoss[source]ο
Bases:
LossPenalize predictions that fall outside a low-dimensional subspace.
Attributes Summary
Methods Summary
__call__(keypoints_pred[,Β stage])Compute the PCA loss for a batch of predicted keypoints.
compute_loss(predictions)Compute per-sample PCA reprojection error.
remove_nans(**kwargs)No-op for PCALoss; NaN handling is performed inside
compute_loss().Attributes Documentation
- LOSS_NAME_MULTIVIEW = 'pca_multiview'ο
- LOSS_NAME_SINGLEVIEW = 'pca_singleview'ο
Methods Documentation
- __call__(keypoints_pred: Tensor, stage: Literal['train', 'val', 'test'] | None = None, **kwargs: Any) tuple[Float[Tensor, ''], list[dict]][source]ο
Compute the PCA loss for a batch of predicted keypoints.
- Parameters:
keypoints_pred β predicted keypoint coordinates.
stage β training stage for logging.
**kwargs β ignored extra keyword arguments.
- Returns:
Tuple of scalar loss and list of logging dicts.
- compute_loss(predictions: Float[Tensor, 'num_samples sample_dim']) Float[Tensor, 'num_samples _'][source]ο
Compute per-sample PCA reprojection error.
- Parameters:
predictions β predicted keypoint coordinates, shape
(num_samples, sample_dim).- Returns:
Reprojection error per sample and keypoint.
- remove_nans(**kwargs: Any) Any[source]ο
No-op for PCALoss; NaN handling is performed inside
compute_loss().
- __init__(loss_name: Literal['pca_singleview', 'pca_multiview'], components_to_keep: int | float = 0.95, empirical_epsilon_percentile: float = 99.0, epsilon: float | None = None, empirical_epsilon_multiplier: float = 1.0, mirrored_column_matches: ListConfig | list | None = None, columns_for_singleview_pca: ListConfig | list | None = None, data_module: BaseDataModule | UnlabeledDataModule | None = None, log_weight: float = 0.0, device: str | device = 'cpu', centering_method: Literal['mean', 'median'] | None = None, **kwargs: Any) None[source]ο
Initialize PCALoss.
Fits a
KeypointPCAobject on the training data and uses the resulting low-dimensional subspace to penalize out-of-subspace predictions at training time.- Parameters:
loss_name β
"pca_singleview"penalizes single-camera predictions;"pca_multiview"penalizes predictions that are inconsistent across views.components_to_keep β passed to
KeypointPCA; see its docstring for details.empirical_epsilon_percentile β percentile of the training-data reprojection error used to set epsilon when
epsilonisNone; in[0, 100].epsilon β if not
None, use this fixed epsilon value and ignoreempirical_epsilon_percentile.empirical_epsilon_multiplier β scalar multiplier applied to the empirically computed epsilon before use.
mirrored_column_matches β required for
"pca_multiview"; seeKeypointPCAfor details.columns_for_singleview_pca β subset of keypoint indices to use for singleview PCA;
Noneuses all keypoints.data_module β data module used by
KeypointPCAto extract training data.log_weight β final weight in front of the loss term in the objective function is computed as
1.0 / (2.0 * exp(log_weight)).device β device on which PCA parameters are stored and loss is computed.
centering_method β if not
None, subtract the per-frame keypoint centroid before fitting PCA."mean"uses the arithmetic mean;"median"uses the median.
- __new__(**kwargs)ο