TemporalLoss

class lightning_pose.losses.losses.TemporalLoss[source]

Bases: Loss

Penalize temporal differences for each target.

Motion model: x_t = x_(t-1) + e_t, e_t ~ N(0, s)

Attributes Summary

loss_name

Methods Summary

__call__(keypoints_pred[, confidences, stage])

Call self as a function.

compute_loss(predictions)

rectify_epsilon(loss)

Rectify supporting a list of epsilons, one per bodypart.

remove_nans(loss, confidences)

Attributes Documentation

loss_name = 'temporal'

Methods Documentation

__call__(keypoints_pred: Tensor, {'__torchtyping__': True, 'details': ('batch', 'two_x_num_keypoints'), 'cls_name': 'TensorType'}], confidences: Tensor, {'__torchtyping__': True, 'details': ('batch', 'num_keypoints'), 'cls_name': 'TensorType'}] | None = None, stage: Literal['train', 'val', 'test'] | None = None, **kwargs) tuple[~torch.Annotated[~torch.Tensor, {'__torchtyping__': True, 'details': ((),), 'cls_name': 'TensorType'}], list[dict]][source]

Call self as a function.

compute_loss(predictions: Tensor, {'__torchtyping__': True, 'details': ('batch', 'two_x_num_keypoints'), 'cls_name': 'TensorType'}]) Tensor, {'__torchtyping__': True, 'details': ('batch_minus_one', 'num_keypoints',), 'cls_name': 'TensorType'}][source]
rectify_epsilon(loss: Tensor, {'__torchtyping__': True, 'details': ('batch_minus_one', 'num_keypoints'), 'cls_name': 'TensorType'}]) Tensor, {'__torchtyping__': True, 'details': ('batch_minus_one', 'num_keypoints',), 'cls_name': 'TensorType'}][source]

Rectify supporting a list of epsilons, one per bodypart. Not implemented in Loss class, because shapes of broadcasting may vary

remove_nans(loss: Tensor, {'__torchtyping__': True, 'details': ('batch_minus_one', 'num_keypoints'), 'cls_name': 'TensorType'}], confidences: Tensor, {'__torchtyping__': True, 'details': ('batch', 'num_keypoints'), 'cls_name': 'TensorType'}]) Tensor, {'__torchtyping__': True, 'details': ('batch_minus_one', 'num_keypoints',), 'cls_name': 'TensorType'}][source]
__init__(data_module: BaseDataModule | UnlabeledDataModule | None = None, epsilon: float | list[float] = 0.0, prob_threshold: float = 0.0, log_weight: float = 0.0, **kwargs) None[source]

Initialize TemporalLoss.

Parameters:
  • data_module – data module providing access to datasets; passed to the parent class.

  • epsilon – loss values below this threshold are zeroed out. May be a scalar or a list with one value per keypoint.

  • prob_threshold – predictions whose confidence is below this value are excluded from the loss computation.

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