_smooth_l1_loss
smooth_l1_loss
¶
Calculate Smooth L1 Loss between two tensors.
This method can be used with TensorFlow tensors:
true = tf.constant([[0,1,0,0], [0,0,0,1], [0,0,1,0], [1,0,0,0]])
pred = tf.constant([[0.1,0.9,0.05,0.05], [0.1,0.2,0.0,0.7], [0.0,0.15,0.8,0.05], [1.0,0.0,0.0,0.0]])
Smooth_L1 = fe.backend.smooth_l1_loss(y_pred=pred, y_true=true, loss_type='smooth', beta=0.65) #[0.0048, 0.0269, 0.0125, 0.0000]
true = tf.constant([[1], [3], [2], [0]])
pred = tf.constant([[2.0], [0.0], [2.0], [1.0]])
Smooth_L1 = fe.backend.smooth_l1_loss(y_pred=pred, y_true=true, loss_type='smooth', beta=0.65) #[0.6750, 2.6750, 0.0000, 0.6750]
This method can be used with PyTorch tensors:
true = torch.tensor([[0,1,0,0], [0,0,0,1], [0,0,1,0], [1,0,0,0]])
pred = torch.tensor([[0.1,0.9,0.05,0.05], [0.1,0.2,0.0,0.7], [0.0,0.15,0.8,0.05], [1.0,0.0,0.0,0.0]])
Smooth_L1 = fe.backend.smooth_l1_loss(y_pred=pred, y_true=true, loss_type='smooth', beta=0.65) #[0.0048, 0.0269, 0.0125, 0.0000]
true = torch.tensor([[1], [3], [2], [0]])
pred = torch.tensor([[2.0], [0.0], [2.0], [1.0]])
Smooth_L1 = fe.backend.smooth_l1_loss(y_pred=pred, y_true=true, loss_type='smooth', beta=0.65) #[0.6750, 2.6750, 0.0000, 0.6750]
Parameters:
Name | Type | Description | Default |
---|---|---|---|
y_true |
Tensor
|
Ground truth class labels with a shape like (batch) or (batch, n_classes). dtype: int, float16, float32. |
required |
y_pred |
Tensor
|
Prediction score for each class, with a shape like y_true. dtype: float32 or float16. |
required |
beta |
float
|
Threshold factor. Needs to be a positive number. dtype: float16 or float32. |
1.0
|
Returns:
Type | Description |
---|---|
Tensor
|
Smooth L1 between |
Raises:
Type | Description |
---|---|
ValueError
|
If |
ValueError
|
If beta is less than 1 for Smooth L1 loss. |