FocalLoss¶
- class mmpretrain.models.losses.FocalLoss(gamma=2.0, alpha=0.25, reduction='mean', loss_weight=1.0)[源代码]¶
Focal loss.
- 参数:
gamma (float) – Focusing parameter in focal loss. Defaults to 2.0.
alpha (float) – The parameter in balanced form of focal loss. Defaults to 0.25.
reduction (str) – The method used to reduce the loss into a scalar. Options are “none” and “mean”. Defaults to ‘mean’.
loss_weight (float) – Weight of loss. Defaults to 1.0.
- forward(pred, target, weight=None, avg_factor=None, reduction_override=None)[源代码]¶
Sigmoid focal loss.
- 参数:
pred (torch.Tensor) – The prediction with shape (N, *).
target (torch.Tensor) – The ground truth label of the prediction with shape (N, *), N or (N,1).
weight (torch.Tensor, optional) – Sample-wise loss weight with shape (N, *). Defaults to None.
avg_factor (int, optional) – Average factor that is used to average the loss. Defaults to None.
reduction_override (str, optional) – The method used to reduce the loss into a scalar. Options are “none”, “mean” and “sum”. Defaults to None.
- 返回:
Loss.
- 返回类型: