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","''","``","}","."]
docstr: Computes the Generalized Dice Score and returns a tensor with its per image values.
  
  Args:
      y_pred (torch.Tensor): binarized segmentation model output. It must be in one-hot format and in the NCHW[D] format,
          where N is the batch dimension, C is the channel dimension, and the remaining are the spatial dimensions.
      y (torch.Tensor): binarized ground-truth. It must be in one-hot format and have the same shape as `y_pred`.
  
  Raises:
      ValueError: if `y_pred` and `y` have less than 3 dimensions, or `y_pred` and `y` don't have the same shape.
docstr_tok: ["Computes","the","Generalized","Dice","Score","and","returns","a","tensor","with","its","per","image","values",".","Args",":","y_pred","(","torch.Tensor",")",":","binarized","segmentation","model","output",".","It","must","be","in","one-hot","format","and","in","the","NCHW","[","D","]","format",",","where","N","is","the","batch","dimension",",","C","is","the","channel","dimension",",","and","the","remaining","are","the","spatial","dimensions",".","y","(","torch.Tensor",")",":","binarized","ground-truth",".","It","must","be","in","one-hot","format","and","have","the","same","shape","as","`","y_pred","`",".","Raises",":","ValueError",":","if","`","y_pred","`","and","`","y","`","have","less","than","3","dimensions",",","or","`","y_pred","`","and","`","y","`","do","n't","have","the","same","shape","."]
code: def _compute_tensor(self, y_pred: torch.Tensor, y: torch.Tensor) -> torch.Tensor:  # type: ignore[override]
      """Computes the Generalized Dice Score and returns a tensor with its per image values.
  
      Args:
          y_pred (torch.Tensor): binarized segmentation model output. It must be in one-hot format and in the NCHW[D] format,
              where N is the batch dimension, C is the channel dimension, and the remaining are the spatial dimensions.
          y (torch.Tensor): binarized ground-truth. It must be in one-hot format and have the same shape as `y_pred`.
  
      Raises:
          ValueError: if `y_pred` and `y` have less than 3 dimensions, or `y_pred` and `y` don't have the same shape.
      """
      return compute_generalized_dice(
          y_pred=y_pred,
          y=y,
          include_background=self.include_background,
          weight_type=self.weight_type,
      )
  
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 2 for calling the GeneralizedDiceScore obj's underlying member method code with example usage: obj._compute_tensor(y_pred, y) and returns: compute_generalized_dice