smooth_l1_loss

Function smooth_l1_loss 

Source
pub fn smooth_l1_loss<B>(
    prediction: &Tensor<B>,
    target: &Tensor<B>,
    beta: f64,
) -> Result<Tensor<B>, Error>
where B: Backend,
Expand description

Smooth L1 Loss (Huber Loss):

            ⎧ 0.5 * (x)² / beta   if |x| < beta
loss(x) =  ⎨
            ⎩ |x| - 0.5 * beta     otherwise

where x = prediction - target.

Transitions smoothly from L2 (near zero) to L1 (far from zero) at beta. Used in Faster R-CNN and SSD for bounding box regression.

§Arguments

  • prediction: predicted values (any shape)
  • target: ground truth values (same shape)
  • beta: threshold at which to switch from L2 to L1 (must be > 0)