KeypointPCA

class lightning_pose.utils.pca.KeypointPCA[source]

Bases: object

Class to collect data from a dataloader and compute PCA params.

Methods Summary

__call__()

Call self as a function.

compute_reprojection_error([data_arr])

returns error per 2D keypoint

pca_prints()

reproject([data_arr])

Reproject a data array using the fixed pca parameters.

Methods Documentation

__call__() None[source]

Call self as a function.

compute_reprojection_error(data_arr: Tensor, {'__torchtyping__': True, 'details': ('num_samples', 'sample_dim'), 'cls_name': 'TensorType'}] | None = None) Tensor, {'__torchtyping__': True, 'details': ('num_samples', 'sample_dim_over_two',), 'cls_name': 'TensorType'}][source]

returns error per 2D keypoint

pca_prints() None[source]
reproject(data_arr: Tensor, {'__torchtyping__': True, 'details': ('num_samples', 'sample_dim'), 'cls_name': 'TensorType'}] | None = None) Tensor, {'__torchtyping__': True, 'details': ('num_samples', 'sample_dim',), 'cls_name': 'TensorType'}][source]

Reproject a data array using the fixed pca parameters.

This transformation is implemented as in scikit-learn https://github.com/scikit-learn/scikit-learn/blob/37ac6788c/sklearn/decomposition/_base.py#L125

__init__(loss_type: Literal['pca_singleview', 'pca_multiview'], data_module: UnlabeledDataModule | BaseDataModule, components_to_keep: int | float | None = 0.99, empirical_epsilon_percentile: float = 99.0, mirrored_column_matches: ListConfig | list | None = None, columns_for_singleview_pca: ListConfig | list | None = None, device: Literal['cpu', 'cuda'] | device = 'cpu', centering_method: Literal['mean', 'median'] | None = None) None[source]

Initialize KeypointPCA.

Parameters:
  • loss_type – type of PCA loss; "pca_singleview" fits PCA on all keypoints from a single camera, "pca_multiview" fits PCA across views of the same keypoints.

  • data_module – data module used to extract labeled training data for fitting PCA.

  • components_to_keep – number of PCA components to retain. An int specifies the exact count; a float in [0, 1] specifies the minimum cumulative explained variance; None keeps all components.

  • empirical_epsilon_percentile – percentile in [0, 100] of the reprojection error distribution used to set the epsilon threshold for the PCA loss.

  • mirrored_column_matches – for multiview data, a list of keypoint index lists — one per camera view — identifying which keypoints correspond across views. For a MultiviewHeatmapDataset, may also be provided as a flat list of per-view keypoint indices that will be expanded automatically.

  • columns_for_singleview_pca – subset of keypoint indices to include when fitting singleview PCA. None uses all keypoints.

  • device – device on which PCA parameters (tensors) are stored.

  • 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)