Shortcuts

Note

You are reading the documentation for MMClassification 0.x, which will soon be deprecated at the end of 2022. We recommend you upgrade to MMClassification 1.0 to enjoy fruitful new features and better performance brought by OpenMMLab 2.0. Check the installation tutorial, migration tutorial and changelog for more details.

FocalLoss

class mmcls.models.FocalLoss(gamma=2.0, alpha=0.25, reduction='mean', loss_weight=1.0)[source]

Focal loss.

Parameters
  • 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)[source]

Sigmoid focal loss.

Parameters
  • 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.

Returns

Loss.

Return type

torch.Tensor

Read the Docs v: master
Versions
master
latest
1.x
dev-1.x
Downloads
html
epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.