class_docstr: AsymmetricUnifiedFocalLoss is a variant of Focal Loss.
  
  Actually, it's only supported for binary image segmentation now
  
  Reimplementation of the Asymmetric Unified Focal Tversky Loss described in:
  
  - "Unified Focal Loss: Generalising Dice and Cross Entropy-based Losses to Handle Class Imbalanced Medical Image Segmentation",
  Michael Yeung, Computerized Medical Imaging and Graphics
class_docstr_tok: ["AsymmetricUnifiedFocalLoss","is","a","variant","of","Focal","Loss",".","Actually",",","it","'s","only","supported","for","binary","image","segmentation","now","Reimplementation","of","the","Asymmetric","Unified","Focal","Tversky","Loss","described","in",":","-","``","Unified","Focal","Loss",":","Generalising","Dice","and","Cross","Entropy-based","Losses","to","Handle","Class","Imbalanced","Medical","Image","Segmentation","''",",","Michael","Yeung",",","Computerized","Medical","Imaging","and","Graphics"]
docstr: Args:
      to_onehot_y : whether to convert `y` into the one-hot format. Defaults to False.
      num_classes : number of classes, it only supports 2 now. Defaults to 2.
      delta : weight of the background. Defaults to 0.7.
      gamma : value of the exponent gamma in the definition of the Focal loss. Defaults to 0.75.
      epsilon : it defines a very small number each time. simmily smooth value. Defaults to 1e-7.
      weight : weight for each loss function, if it's none it's 0.5. Defaults to None.
  
  Example:
      >>> import torch
      >>> from monai.losses import AsymmetricUnifiedFocalLoss
      >>> pred = torch.ones((1,1,32,32), dtype=torch.float32)
      >>> grnd = torch.ones((1,1,32,32), dtype=torch.int64)
      >>> fl = AsymmetricUnifiedFocalLoss(to_onehot_y=True)
      >>> fl(pred, grnd)
docstr_tok: ["Args",":","to_onehot_y",":","whether","to","convert","`","y","`","into","the","one-hot","format",".","Defaults","to","False",".","num_classes",":","number","of","classes",",","it","only","supports","2","now",".","Defaults","to","2.","delta",":","weight","of","the","background",".","Defaults","to","0.7.","gamma",":","value","of","the","exponent","gamma","in","the","definition","of","the","Focal","loss",".","Defaults","to","0.75.","epsilon",":","it","defines","a","very","small","number","each","time",".","simmily","smooth","value",".","Defaults","to","1e-7",".","weight",":","weight","for","each","loss","function",",","if","it","'s","none","it","'s","0.5",".","Defaults","to","None",".","Example",":",">",">",">","import","torch",">",">",">","from","monai.losses","import","AsymmetricUnifiedFocalLoss",">",">",">","pred","=","torch.ones","(","(","1,1,32,32",")",",","dtype=torch.float32",")",">",">",">","grnd","=","torch.ones","(","(","1,1,32,32",")",",","dtype=torch.int64",")",">",">",">","fl","=","AsymmetricUnifiedFocalLoss","(","to_onehot_y=True",")",">",">",">","fl","(","pred",",","grnd",")"]
code: def __init__(
      self,
      to_onehot_y: bool = False,
      num_classes: int = 2,
      weight: float = 0.5,
      gamma: float = 0.5,
      delta: float = 0.7,
      reduction: LossReduction | str = LossReduction.MEAN,
  ):
      """
      Args:
          to_onehot_y : whether to convert `y` into the one-hot format. Defaults to False.
          num_classes : number of classes, it only supports 2 now. Defaults to 2.
          delta : weight of the background. Defaults to 0.7.
          gamma : value of the exponent gamma in the definition of the Focal loss. Defaults to 0.75.
          epsilon : it defines a very small number each time. simmily smooth value. Defaults to 1e-7.
          weight : weight for each loss function, if it's none it's 0.5. Defaults to None.
  
      Example:
          >>> import torch
          >>> from monai.losses import AsymmetricUnifiedFocalLoss
          >>> pred = torch.ones((1,1,32,32), dtype=torch.float32)
          >>> grnd = torch.ones((1,1,32,32), dtype=torch.int64)
          >>> fl = AsymmetricUnifiedFocalLoss(to_onehot_y=True)
          >>> fl(pred, grnd)
      """
      super().__init__(reduction=LossReduction(reduction).value)
      self.to_onehot_y = to_onehot_y
      self.num_classes = num_classes
      self.gamma = gamma
      self.delta = delta
      self.weight: float = weight
      self.asy_focal_loss = AsymmetricFocalLoss(
          gamma=self.gamma, delta=self.delta
      )
      self.asy_focal_tversky_loss = AsymmetricFocalTverskyLoss(
          gamma=self.gamma, delta=self.delta
      )
  
file_path: MONAI/monai/losses/unified_focal_loss.py
imports: from __future__ import annotations
  import warnings
  import torch
  from torch.nn.modules.loss import _Loss
  from monai.networks import one_hot
  from monai.utils import LossReduction
label_desc: Use image node_id 1 to create a new AsymmetricUnifiedFocalLoss object from inherited base classes: _Loss with example: obj = AsymmetricUnifiedFocalLoss(to_onehot_y, num_classes, weight, gamma, delta, reduction)