vis4d.op.loss.common¶
Common loss functions.
Functions
|
L1 loss. |
|
L2 loss. |
|
Rotation loss. |
|
Smooth L1 loss. |
- l1_loss(pred, target, reducer=<function identity_loss>)[source]¶
L1 loss.
- Parameters:
pred (Tensor) – Model predictions
target (Tensor) – Ground truth value
reducer (LossReducer) – Reducer to reduce the loss value. Defaults to identy_loss, which is no reduction.
- Returns:
The reduced L1 loss (reduce(|pred - target|))
- Return type:
Tensor
- l2_loss(pred, target, reducer=<function identity_loss>)[source]¶
L2 loss.
- Parameters:
pred (Tensor) – Model predictions
target (Tensor) – Ground truth value
reducer (LossReducer) – Reducer to reduce the loss value. Defaults to identy_loss, which is no reduction.
- Returns:
The reduced L2 loss (reduce((pred - target)**2))
- Return type:
Tensor
- rotation_loss(pred, target_bin, target_res, num_bins, reducer=<function identity_loss>)[source]¶
Rotation loss.
Consists of bin-based classification loss and residual-based regression loss.
- Parameters:
pred (Tensor) – Prediction shape [B, num_bins * 3]
target_bin (Tensor) – Target bins shape [B, num_bin]
target_res (Tensor) – Target residual shape [B, num_bin]
num_bins (int) – Number of bins
reducer (LossReducer, optional) – Loss Reducer. Defaults to identity_loss.
- Returns:
The reduced loss value
- Return type:
Tensor
- smooth_l1_loss(pred, target, reducer=<function identity_loss>, beta=1.0)[source]¶
Smooth L1 loss.
L1 loss that uses a squared term if the absolute element-wise error falls below beta.
- Parameters:
pred (Tensor) – Model predictions
target (Tensor) – Ground truth value
reducer (LossReducer) – Reducer to reduce the loss value. Defaults to identy_loss, which is no reduction.
beta (float) – Specifies the threshold at which to change between L1 and L2 loss. The value must be non-negative. Default: 1.0
- Returns:
- The reduced smooth l1 loss:
|pred - target| - 0.5*beta if |pred - target| < 0.5*beta (pred - target)^2 * 0.5/beta else
- Return type:
Tensor