class_docstr: Compute the Generalized Dice Score metric between tensors, as the complement of the Generalized Dice Loss defined in:
  
  Sudre, C. et. al. (2017) Generalised Dice overlap as a deep learning
      loss function for highly unbalanced segmentations. DLMIA 2017.
  
  The inputs `y_pred` and `y` are expected to be one-hot, binarized channel-first
  or batch-first tensors, i.e., CHW[D] or BCHW[D].
  
  Example of the typical execution steps of this metric class follows :py:class:`monai.metrics.metric.Cumulative`.
  
  Args:
      include_background (bool, optional): whether to include the background class (assumed to be in channel 0), in the
          score computation. Defaults to True.
      reduction (str, optional): define mode of reduction to the metrics. Available reduction modes:
          {``"none"``, ``"mean_batch"``, ``"sum_batch"``}. Default to ``"mean_batch"``. If "none", will not do reduction.
      weight_type (Union[Weight, str], optional): {``"square"``, ``"simple"``, ``"uniform"``}. Type of function to transform
          ground truth volume into a weight factor. Defaults to ``"square"``.
  
  Raises:
      ValueError: when the `weight_type` is not one of {``"none"``, ``"mean"``, ``"sum"``}.
class_docstr_tok: ["Compute","the","Generalized","Dice","Score","metric","between","tensors",",","as","the","complement","of","the","Generalized","Dice","Loss","defined","in",":","Sudre",",","C.","et",".","al",".","(","2017",")","Generalised","Dice","overlap","as","a","deep","learning","loss","function","for","highly","unbalanced","segmentations",".","DLMIA","2017",".","The","inputs","`","y_pred","`","and","`","y","`","are","expected","to","be","one-hot",",","binarized","channel-first","or","batch-first","tensors",",","i.e.",",","CHW","[","D","]","or","BCHW","[","D","]",".","Example","of","the","typical","execution","steps","of","this","metric","class","follows",":","py",":","class",":","`","monai.metrics.metric.Cumulative","`",".","Args",":","include_background","(","bool",",","optional",")",":","whether","to","include","the","background","class","(","assumed","to","be","in","channel","0",")",",","in","the","score","computation",".","Defaults","to","True",".","reduction","(","str",",","optional",")",":","define","mode","of","reduction","to","the","metrics",".","Available","reduction","modes",":","{","``","``","none","''","``",",","``","``","mean_batch","''","``",",","``","``","sum_batch","''","``","}",".","Default","to","``","``","mean_batch","''","``",".","If","``","none","''",",","will","not","do","reduction",".","weight_type","(","Union","[","Weight",",","str","]",",","optional",")",":","{","``","``","square","''","``",",","``","``","simple","''","``",",","``","``","uniform","''","``","}",".","Type","of","function","to","transform","ground","truth","volume","into","a","weight","factor",".","Defaults","to","``","``","square","''","``",".","Raises",":","ValueError",":","when","the","`","weight_type","`","is","not","one","of","{","``","``","none","''","``",",","``","``","mean","''","``",",","``","``","sum","''","``","}","."]
code: def __init__(
      self,
      include_background: bool = True,
      reduction: MetricReduction | str = MetricReduction.MEAN_BATCH,
      weight_type: Weight | str = Weight.SQUARE,
  ) -> None:
      super().__init__()
      self.include_background = include_background
      reduction_options = [
          "none",
          "mean_batch",
          "sum_batch",
          MetricReduction.NONE,
          MetricReduction.MEAN_BATCH,
          MetricReduction.SUM_BATCH,
      ]
      self.reduction = reduction
      if self.reduction not in reduction_options:
          raise ValueError(
              f"reduction must be one of {reduction_options}"
          )
      self.weight_type = look_up_option(weight_type, Weight)
  
file_path: MONAI/monai/metrics/generalized_dice.py
imports: from __future__ import annotations
  import torch
  from monai.metrics.utils import do_metric_reduction, ignore_background
  from monai.utils import MetricReduction, Weight, look_up_option
  from .metric import CumulativeIterationMetric
label_desc: Use image node_id 1 to create a new GeneralizedDiceScore object from inherited base classes: CumulativeIterationMetric with example: obj = GeneralizedDiceScore(include_background, reduction, weight_type)