Skip to main content

ClikaRT::ops::smooth_l1_loss

function

smooth_l1_loss()

Tensor smooth_l1_loss(
    Tensor input,
    Tensor target,
    Reduction reduction = Reduction::Mean,
    double beta = 1.0
)

Smooth-L1 loss: quadratic within beta of zero, L1 beyond it.

i={12(xiyi)2/βxiyiβxiyi12βotherwise\ell_i = \begin{cases} \tfrac{1}{2}(x_i - y_i)^2/\beta & |x_i - y_i| \le \beta \\ |x_i - y_i| - \tfrac{1}{2}\beta & \text{otherwise} \end{cases}

beta == 0 degenerates to plain L1.

Parameters

  • input: predictions; float dtype.
  • target: ground truth; same shape as input.
  • reduction: None / Mean / Sum; default Mean.
  • beta: the L2-to-L1 knee; default 1.0.

Returns: the loss (0-D under Mean/Sum).

Throws

  • ClikaRT::Error: (INVALID_ARGUMENT) on an input/target shape mismatch.

Declared in ClikaRT/compute/ops.h, line 3036