FocalLoss#

class torch_uncertainty.losses.FocalLoss(gamma, alpha=None, reduction='mean')[source]#

Focal-Loss for classification tasks.

Parameters:
  • gamma (float, optional) – A constant, as described in the paper.

  • alpha (Tensor, optional) – Weights for each class. Defaults to None.

  • reduction (str, optional) – 'mean', 'sum' or 'none'. Defaults to 'mean'.

References

[1] Lin, T.-Y., Goyal, P., Girshick, R., He, K., & Dollár, P. (2017). Focal Loss for Dense Object Detection..

[2] Inspired by AdeelH/pytorch-multi-class-focal-loss .