class_docstr: Compute both Dice loss and Focal Loss, and return the weighted sum of these two losses.
  The details of Dice loss is shown in ``monai.losses.DiceLoss``.
  The details of Focal Loss is shown in ``monai.losses.FocalLoss``.
  
  ``gamma`` and ``lambda_focal`` are only used for the focal loss.
  ``include_background``, ``weight`` and ``reduction`` are used for both losses
  and other parameters are only used for dice loss.
class_docstr_tok: ["Compute","both","Dice","loss","and","Focal","Loss",",","and","return","the","weighted","sum","of","these","two","losses",".","The","details","of","Dice","loss","is","shown","in","``","monai.losses.DiceLoss","``",".","The","details","of","Focal","Loss","is","shown","in","``","monai.losses.FocalLoss","``",".","``","gamma","``","and","``","lambda_focal","``","are","only","used","for","the","focal","loss",".","``","include_background","``",",","``","weight","``","and","``","reduction","``","are","used","for","both","losses","and","other","parameters","are","only","used","for","dice","loss","."]
docstr: Args:
      include_background: if False channel index 0 (background category) is excluded from the calculation.
      to_onehot_y: whether to convert the ``target`` into the one-hot format,
          using the number of classes inferred from `input` (``input.shape[1]``). Defaults to False.
      sigmoid: if True, apply a sigmoid function to the prediction, only used by the `DiceLoss`,
          don't need to specify activation function for `FocalLoss`.
      softmax: if True, apply a softmax function to the prediction, only used by the `DiceLoss`,
          don't need to specify activation function for `FocalLoss`.
      other_act: callable function to execute other activation layers, Defaults to ``None``.
          for example: `other_act = torch.tanh`. only used by the `DiceLoss`, not for `FocalLoss`.
      squared_pred: use squared versions of targets and predictions in the denominator or not.
      jaccard: compute Jaccard Index (soft IoU) instead of dice or not.
      reduction: {``"none"``, ``"mean"``, ``"sum"``}
          Specifies the reduction to apply to the output. Defaults to ``"mean"``.
  
          - ``"none"``: no reduction will be applied.
          - ``"mean"``: the sum of the output will be divided by the number of elements in the output.
          - ``"sum"``: the output will be summed.
  
      smooth_nr: a small constant added to the numerator to avoid zero.
      smooth_dr: a small constant added to the denominator to avoid nan.
      batch: whether to sum the intersection and union areas over the batch dimension before the dividing.
          Defaults to False, a Dice loss value is computed independently from each item in the batch
          before any `reduction`.
      gamma: value of the exponent gamma in the definition of the Focal loss.
      weight: weights to apply to the voxels of each class. If None no weights are applied.
          The input can be a single value (same weight for all classes), a sequence of values (the length
          of the sequence should be the same as the number of classes).
      lambda_dice: the trade-off weight value for dice loss. The value should be no less than 0.0.
          Defaults to 1.0.
      lambda_focal: the trade-off weight value for focal loss. The value should be no less than 0.0.
          Defaults to 1.0.
docstr_tok: ["Args",":","include_background",":","if","False","channel","index","0","(","background","category",")","is","excluded","from","the","calculation",".","to_onehot_y",":","whether","to","convert","the","``","target","``","into","the","one-hot","format",",","using","the","number","of","classes","inferred","from","`","input","`","(","``","input.shape","[","1","]","``",")",".","Defaults","to","False",".","sigmoid",":","if","True",",","apply","a","sigmoid","function","to","the","prediction",",","only","used","by","the","`","DiceLoss","`",",","do","n't","need","to","specify","activation","function","for","`","FocalLoss","`",".","softmax",":","if","True",",","apply","a","softmax","function","to","the","prediction",",","only","used","by","the","`","DiceLoss","`",",","do","n't","need","to","specify","activation","function","for","`","FocalLoss","`",".","other_act",":","callable","function","to","execute","other","activation","layers",",","Defaults","to","``","None","``",".","for","example",":","`","other_act","=","torch.tanh","`",".","only","used","by","the","`","DiceLoss","`",",","not","for","`","FocalLoss","`",".","squared_pred",":","use","squared","versions","of","targets","and","predictions","in","the","denominator","or","not",".","jaccard",":","compute","Jaccard","Index","(","soft","IoU",")","instead","of","dice","or","not",".","reduction",":","{","``","``","none","''","``",",","``","``","mean","''","``",",","``","``","sum","''","``","}","Specifies","the","reduction","to","apply","to","the","output",".","Defaults","to","``","``","mean","''","``",".","-","``","``","none","''","``",":","no","reduction","will","be","applied",".","-","``","``","mean","''","``",":","the","sum","of","the","output","will","be","divided","by","the","number","of","elements","in","the","output",".","-","``","``","sum","''","``",":","the","output","will","be","summed",".","smooth_nr",":","a","small","constant","added","to","the","numerator","to","avoid","zero",".","smooth_dr",":","a","small","constant","added","to","the","denominator","to","avoid","nan",".","batch",":","whether","to","sum","the","intersection","and","union","areas","over","the","batch","dimension","before","the","dividing",".","Defaults","to","False",",","a","Dice","loss","value","is","computed","independently","from","each","item","in","the","batch","before","any","`","reduction","`",".","gamma",":","value","of","the","exponent","gamma","in","the","definition","of","the","Focal","loss",".","weight",":","weights","to","apply","to","the","voxels","of","each","class",".","If","None","no","weights","are","applied",".","The","input","can","be","a","single","value","(","same","weight","for","all","classes",")",",","a","sequence","of","values","(","the","length","of","the","sequence","should","be","the","same","as","the","number","of","classes",")",".","lambda_dice",":","the","trade-off","weight","value","for","dice","loss",".","The","value","should","be","no","less","than","0.0",".","Defaults","to","1.0.","lambda_focal",":","the","trade-off","weight","value","for","focal","loss",".","The","value","should","be","no","less","than","0.0",".","Defaults","to","1.0","."]
code: def __init__(
      self,
      include_background: bool = True,
      to_onehot_y: bool = False,
      sigmoid: bool = False,
      softmax: bool = False,
      other_act: Callable | None = None,
      squared_pred: bool = False,
      jaccard: bool = False,
      reduction: str = "mean",
      smooth_nr: float = 1e-5,
      smooth_dr: float = 1e-5,
      batch: bool = False,
      gamma: float = 2.0,
      focal_weight: Sequence[float]
      | float
      | int
      | torch.Tensor
      | None = None,
      weight: Sequence[float]
      | float
      | int
      | torch.Tensor
      | None = None,
      lambda_dice: float = 1.0,
      lambda_focal: float = 1.0,
  ) -> None:
      """
      Args:
          include_background: if False channel index 0 (background category) is excluded from the calculation.
          to_onehot_y: whether to convert the ``target`` into the one-hot format,
              using the number of classes inferred from `input` (``input.shape[1]``). Defaults to False.
          sigmoid: if True, apply a sigmoid function to the prediction, only used by the `DiceLoss`,
              don't need to specify activation function for `FocalLoss`.
          softmax: if True, apply a softmax function to the prediction, only used by the `DiceLoss`,
              don't need to specify activation function for `FocalLoss`.
          other_act: callable function to execute other activation layers, Defaults to ``None``.
              for example: `other_act = torch.tanh`. only used by the `DiceLoss`, not for `FocalLoss`.
          squared_pred: use squared versions of targets and predictions in the denominator or not.
          jaccard: compute Jaccard Index (soft IoU) instead of dice or not.
          reduction: {``"none"``, ``"mean"``, ``"sum"``}
              Specifies the reduction to apply to the output. Defaults to ``"mean"``.
  
              - ``"none"``: no reduction will be applied.
              - ``"mean"``: the sum of the output will be divided by the number of elements in the output.
              - ``"sum"``: the output will be summed.
  
          smooth_nr: a small constant added to the numerator to avoid zero.
          smooth_dr: a small constant added to the denominator to avoid nan.
          batch: whether to sum the intersection and union areas over the batch dimension before the dividing.
              Defaults to False, a Dice loss value is computed independently from each item in the batch
              before any `reduction`.
          gamma: value of the exponent gamma in the definition of the Focal loss.
          weight: weights to apply to the voxels of each class. If None no weights are applied.
              The input can be a single value (same weight for all classes), a sequence of values (the length
              of the sequence should be the same as the number of classes).
          lambda_dice: the trade-off weight value for dice loss. The value should be no less than 0.0.
              Defaults to 1.0.
          lambda_focal: the trade-off weight value for focal loss. The value should be no less than 0.0.
              Defaults to 1.0.
  
      """
      super().__init__()
      weight = focal_weight if focal_weight is not None else weight
      self.dice = DiceLoss(
          include_background=include_background,
          to_onehot_y=False,
          sigmoid=sigmoid,
          softmax=softmax,
          other_act=other_act,
          squared_pred=squared_pred,
          jaccard=jaccard,
          reduction=reduction,
          smooth_nr=smooth_nr,
          smooth_dr=smooth_dr,
          batch=batch,
          weight=weight,
      )
      self.focal = FocalLoss(
          include_background=include_background,
          to_onehot_y=False,
          gamma=gamma,
          weight=weight,
          reduction=reduction,
      )
      if lambda_dice < 0.0:
          raise ValueError("lambda_dice should be no less than 0.0.")
      if lambda_focal < 0.0:
          raise ValueError("lambda_focal should be no less than 0.0.")
      self.lambda_dice = lambda_dice
      self.lambda_focal = lambda_focal
      self.to_onehot_y = to_onehot_y
  
imports: from __future__ import annotations
  import warnings
  from collections.abc import Callable, Sequence
  from typing import Any
  import numpy
  import torch
  import torch.nn
  import torch.nn.functional
  from torch.nn.modules.loss import _Loss
  from monai.losses.focal_loss import FocalLoss
  from monai.losses.spatial_mask import MaskedLoss
  from monai.networks import one_hot
  from monai.utils import DiceCEReduction, LossReduction, Weight, deprecated_arg, look_up_option, pytorch_after
label_desc: Use image node_id 1 to create a new DiceFocalLoss object from inherited base classes: _Loss with example: obj = DiceFocalLoss(include_background, to_onehot_y, sigmoid, softmax, other_act, squared_pred, jaccard, reduction, smooth_nr, smooth_dr, batch, gamma, focal_weight, weight, lambda_dice, lambda_focal)