Lossο
- class lightning_pose.losses.losses.Loss[source]ο
Bases:
objectParent class for all losses.
Attributes Summary
Scalar loss weight computed as
1 / (2 * exp(log_weight)).Methods Summary
__call__(*args,Β **kwargs)Execute the full loss pipeline and return a scalar loss plus logging dicts.
compute_loss(**kwargs)Compute the element-wise loss between targets and predictions.
log_loss(loss,Β stage)Build a list of logging dicts for the scalar loss and its weight.
rectify_epsilon(loss)Zero out loss values below the epsilon threshold (epsilon-insensitive loss).
reduce_loss(loss[,Β method])Reduce an element-wise loss tensor to a scalar.
remove_nans(**kwargs)Remove NaN entries from inputs before computing the loss.
Attributes Documentation
- weightο
Scalar loss weight computed as
1 / (2 * exp(log_weight)).- Returns:
Positive scalar weight tensor.
Methods Documentation
- __call__(*args: Any, **kwargs: Any) tuple[Float[Tensor, ''], list[dict]][source]ο
Execute the full loss pipeline and return a scalar loss plus logging dicts.
The standard pipeline is: remove_nans β compute_loss β rectify_epsilon β reduce_loss β log_loss. Subclasses must override this method to supply the correct arguments to each step.
- Raises:
NotImplementedError β always, unless overridden by a subclass.
- compute_loss(**kwargs: Any) Tensor[source]ο
Compute the element-wise loss between targets and predictions.
Subclasses must override this method.
- Raises:
NotImplementedError β always, unless overridden by a subclass.
- log_loss(loss: Tensor, stage: Literal['train', 'val', 'test'] | None) list[dict][source]ο
Build a list of logging dicts for the scalar loss and its weight.
- Parameters:
loss β scalar loss value to log.
stage β training stage prefix for the log key, or
Noneto skip stage prefixing.
- Returns:
List of dicts with
"name"and"value"keys, one for the loss and one for the weight.
- rectify_epsilon(loss: Tensor) Tensor[source]ο
Zero out loss values below the epsilon threshold (epsilon-insensitive loss).
- Parameters:
loss β element-wise loss tensor.
- Returns:
Loss tensor with values below
self.epsilonset to zero via ReLU.
- reduce_loss(loss: Tensor, method: str = 'mean') Float[Tensor, ''][source]ο
Reduce an element-wise loss tensor to a scalar.
- Parameters:
loss β element-wise loss tensor.
method β reduction method; currently
"mean"or"sum".
- Returns:
Scalar loss tensor.
- remove_nans(**kwargs: Any) Any[source]ο
Remove NaN entries from inputs before computing the loss.
Subclasses must override this method to implement the appropriate NaN-masking strategy.
- Raises:
NotImplementedError β always, unless overridden by a subclass.
- __init__(data_module: BaseDataModule | UnlabeledDataModule | None = None, epsilon: float | list[float] = 0.0, log_weight: float = 0.0, **kwargs: Any) None[source]ο
- Parameters:
data_module β give losses access to data for computing data-specific loss params
epsilon β loss values below epsilon will be zeroed out
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)ο