class_docstr: Compute both Generalized Dice Loss and Focal Loss, and return their weighted average. The details of Generalized Dice Loss
  and Focal Loss are available at ``monai.losses.GeneralizedDiceLoss`` and ``monai.losses.FocalLoss``.
  
  Args:
      include_background (bool, optional): if False channel index 0 (background category) is excluded from the calculation.
          Defaults to True.
      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 (bool, optional): if True, apply a sigmoid function to the prediction. Defaults to False.
      softmax (bool, optional): if True, apply a softmax function to the prediction. Defaults to False.
      other_act (Optional[Callable], optional): callable function to execute other activation layers,
          Defaults to ``None``. for example: `other_act = torch.tanh`.
          only used by the `GeneralizedDiceLoss`, not for the `FocalLoss`.
      w_type (Union[Weight, str], optional): {``"square"``, ``"simple"``, ``"uniform"``}. Type of function to transform
          ground-truth volume to a weight factor. Defaults to ``"square"``.
      reduction (Union[LossReduction, str], optional): {``"none"``, ``"mean"``, ``"sum"``}. Specified 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 (float, optional): a small constant added to the numerator to avoid zero. Defaults to 1e-5.
      smooth_dr (float, optional): a small constant added to the denominator to avoid nan. Defaults to 1e-5.
      batch (bool, optional): whether to sum the intersection and union areas over the batch dimension before the dividing.
          Defaults to False, i.e., the areas are computed for each item in the batch.
      gamma (float, optional): value of the exponent gamma in the definition of the Focal loss. Defaults to 2.0.
      weight (Optional[Union[Sequence[float], float, int, torch.Tensor]], optional): 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 hould be the same as
          the number of classes). Defaults to None.
      lambda_gdl (float, optional): the trade-off weight value for Generalized Dice Loss. The value should be
          no less than 0.0. Defaults to 1.0.
      lambda_focal (float, optional): the trade-off weight value for Focal Loss. The value should be no less
          than 0.0. Defaults to 1.0.
  
  Raises:
      ValueError: if either `lambda_gdl` or `lambda_focal` is less than 0.
class_docstr_tok: ["Compute","both","Generalized","Dice","Loss","and","Focal","Loss",",","and","return","their","weighted","average",".","The","details","of","Generalized","Dice","Loss","and","Focal","Loss","are","available","at","``","monai.losses.GeneralizedDiceLoss","``","and","``","monai.losses.FocalLoss","``",".","Args",":","include_background","(","bool",",","optional",")",":","if","False","channel","index","0","(","background","category",")","is","excluded","from","the","calculation",".","Defaults","to","True",".","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","(","bool",",","optional",")",":","if","True",",","apply","a","sigmoid","function","to","the","prediction",".","Defaults","to","False",".","softmax","(","bool",",","optional",")",":","if","True",",","apply","a","softmax","function","to","the","prediction",".","Defaults","to","False",".","other_act","(","Optional","[","Callable","]",",","optional",")",":","callable","function","to","execute","other","activation","layers",",","Defaults","to","``","None","``",".","for","example",":","`","other_act","=","torch.tanh","`",".","only","used","by","the","`","GeneralizedDiceLoss","`",",","not","for","the","`","FocalLoss","`",".","w_type","(","Union","[","Weight",",","str","]",",","optional",")",":","{","``","``","square","''","``",",","``","``","simple","''","``",",","``","``","uniform","''","``","}",".","Type","of","function","to","transform","ground-truth","volume","to","a","weight","factor",".","Defaults","to","``","``","square","''","``",".","reduction","(","Union","[","LossReduction",",","str","]",",","optional",")",":","{","``","``","none","''","``",",","``","``","mean","''","``",",","``","``","sum","''","``","}",".","Specified","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","(","float",",","optional",")",":","a","small","constant","added","to","the","numerator","to","avoid","zero",".","Defaults","to","1e-5",".","smooth_dr","(","float",",","optional",")",":","a","small","constant","added","to","the","denominator","to","avoid","nan",".","Defaults","to","1e-5",".","batch","(","bool",",","optional",")",":","whether","to","sum","the","intersection","and","union","areas","over","the","batch","dimension","before","the","dividing",".","Defaults","to","False",",","i.e.",",","the","areas","are","computed","for","each","item","in","the","batch",".","gamma","(","float",",","optional",")",":","value","of","the","exponent","gamma","in","the","definition","of","the","Focal","loss",".","Defaults","to","2.0.","weight","(","Optional","[","Union","[","Sequence","[","float","]",",","float",",","int",",","torch.Tensor","]","]",",","optional",")",":","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","hould","be","the","same","as","the","number","of","classes",")",".","Defaults","to","None",".","lambda_gdl","(","float",",","optional",")",":","the","trade-off","weight","value","for","Generalized","Dice","Loss",".","The","value","should","be","no","less","than","0.0",".","Defaults","to","1.0.","lambda_focal","(","float",",","optional",")",":","the","trade-off","weight","value","for","Focal","Loss",".","The","value","should","be","no","less","than","0.0",".","Defaults","to","1.0",".","Raises",":","ValueError",":","if","either","`","lambda_gdl","`","or","`","lambda_focal","`","is","less","than","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,
      w_type: Weight | str = Weight.SQUARE,
      reduction: LossReduction | str = LossReduction.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_gdl: float = 1.0,
      lambda_focal: float = 1.0,
  ) -> None:
      super().__init__()
      self.generalized_dice = GeneralizedDiceLoss(
          include_background=include_background,
          to_onehot_y=to_onehot_y,
          sigmoid=sigmoid,
          softmax=softmax,
          other_act=other_act,
          w_type=w_type,
          reduction=reduction,
          smooth_nr=smooth_nr,
          smooth_dr=smooth_dr,
          batch=batch,
      )
      weight = focal_weight if focal_weight is not None else weight
      self.focal = FocalLoss(
          include_background=include_background,
          to_onehot_y=to_onehot_y,
          gamma=gamma,
          weight=weight,
          reduction=reduction,
      )
      if lambda_gdl < 0.0:
          raise ValueError("lambda_gdl 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_gdl = lambda_gdl
      self.lambda_focal = lambda_focal
  
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 GeneralizedDiceFocalLoss object from inherited base classes: _Loss with example: obj = GeneralizedDiceFocalLoss(include_background, to_onehot_y, sigmoid, softmax, other_act, w_type, reduction, smooth_nr, smooth_dr, batch, gamma, focal_weight, weight, lambda_gdl, lambda_focal)