class_docstr: Compute Dice score between two tensors `y_pred` and `y`.
  `y_pred` and `y` can be single-channel class indices or in the one-hot format.
  
  Example:
  
  .. code-block:: python
  
      import torch
      from monai.metrics import DiceHelper
  
      n_classes, batch_size = 5, 16
      spatial_shape = (128, 128, 128)
  
      y_pred = torch.rand(batch_size, n_classes, *spatial_shape).float()  # predictions
      y = torch.randint(0, n_classes, size=(batch_size, 1, *spatial_shape)).long()  # ground truth
  
      score, not_nans = DiceHelper(include_background=False, sigmoid=True, softmax=True)(y_pred, y)
      print(score, not_nans)
class_docstr_tok: ["Compute","Dice","score","between","two","tensors","`","y_pred","`","and","`","y","`",".","`","y_pred","`","and","`","y","`","can","be","single-channel","class","indices","or","in","the","one-hot","format",".","Example",":","..","code-block",":",":","python","import","torch","from","monai.metrics","import","DiceHelper","n_classes",",","batch_size","=","5",",","16","spatial_shape","=","(","128",",","128",",","128",")","y_pred","=","torch.rand","(","batch_size",",","n_classes",",","*","spatial_shape",")",".float","(",")","#","predictions","y","=","torch.randint","(","0",",","n_classes",",","size=","(","batch_size",",","1",",","*","spatial_shape",")",")",".long","(",")","#","ground","truth","score",",","not_nans","=","DiceHelper","(","include_background=False",",","sigmoid=True",",","softmax=True",")","(","y_pred",",","y",")","print","(","score",",","not_nans",")"]
docstr: Args:
      include_background: whether to include the score on the first channel
          (default to the value of `sigmoid`, False).
      sigmoid: whether ``y_pred`` are/will be sigmoid activated outputs. If True, thresholding at 0.5
          will be performed to get the discrete prediction. Defaults to False.
      softmax: whether ``y_pred`` are softmax activated outputs. If True, `argmax` will be performed to
          get the discrete prediction. Defaults to the value of ``not sigmoid``.
      activate: whether to apply sigmoid to ``y_pred`` if ``sigmoid`` is True. Defaults to False.
          This option is only valid when ``sigmoid`` is True.
      get_not_nans: whether to return the number of not-nan values.
      reduction: define mode of reduction to the metrics
      ignore_empty: if `True`, NaN value will be set for empty ground truth cases.
          If `False`, 1 will be set if the Union of ``y_pred`` and ``y`` is empty.
      num_classes: number of input channels (always including the background). When this is None,
          ``y_pred.shape[1]`` will be used. This option is useful when both ``y_pred`` and ``y`` are
          single-channel class indices and the number of classes is not automatically inferred from data.
docstr_tok: ["Args",":","include_background",":","whether","to","include","the","score","on","the","first","channel","(","default","to","the","value","of","`","sigmoid","`",",","False",")",".","sigmoid",":","whether","``","y_pred","``","are\/will","be","sigmoid","activated","outputs",".","If","True",",","thresholding","at","0.5","will","be","performed","to","get","the","discrete","prediction",".","Defaults","to","False",".","softmax",":","whether","``","y_pred","``","are","softmax","activated","outputs",".","If","True",",","`","argmax","`","will","be","performed","to","get","the","discrete","prediction",".","Defaults","to","the","value","of","``","not","sigmoid","``",".","activate",":","whether","to","apply","sigmoid","to","``","y_pred","``","if","``","sigmoid","``","is","True",".","Defaults","to","False",".","This","option","is","only","valid","when","``","sigmoid","``","is","True",".","get_not_nans",":","whether","to","return","the","number","of","not-nan","values",".","reduction",":","define","mode","of","reduction","to","the","metrics","ignore_empty",":","if","`","True","`",",","NaN","value","will","be","set","for","empty","ground","truth","cases",".","If","`","False","`",",","1","will","be","set","if","the","Union","of","``","y_pred","``","and","``","y","``","is","empty",".","num_classes",":","number","of","input","channels","(","always","including","the","background",")",".","When","this","is","None",",","``","y_pred.shape","[","1","]","``","will","be","used",".","This","option","is","useful","when","both","``","y_pred","``","and","``","y","``","are","single-channel","class","indices","and","the","number","of","classes","is","not","automatically","inferred","from","data","."]
code: def __init__(
      self,
      include_background: bool | None = None,
      sigmoid: bool = False,
      softmax: bool | None = None,
      activate: bool = False,
      get_not_nans: bool = True,
      reduction: MetricReduction | str = MetricReduction.MEAN_BATCH,
      ignore_empty: bool = True,
      num_classes: int | None = None,
  ) -> None:
      """
  
      Args:
          include_background: whether to include the score on the first channel
              (default to the value of `sigmoid`, False).
          sigmoid: whether ``y_pred`` are/will be sigmoid activated outputs. If True, thresholding at 0.5
              will be performed to get the discrete prediction. Defaults to False.
          softmax: whether ``y_pred`` are softmax activated outputs. If True, `argmax` will be performed to
              get the discrete prediction. Defaults to the value of ``not sigmoid``.
          activate: whether to apply sigmoid to ``y_pred`` if ``sigmoid`` is True. Defaults to False.
              This option is only valid when ``sigmoid`` is True.
          get_not_nans: whether to return the number of not-nan values.
          reduction: define mode of reduction to the metrics
          ignore_empty: if `True`, NaN value will be set for empty ground truth cases.
              If `False`, 1 will be set if the Union of ``y_pred`` and ``y`` is empty.
          num_classes: number of input channels (always including the background). When this is None,
              ``y_pred.shape[1]`` will be used. This option is useful when both ``y_pred`` and ``y`` are
              single-channel class indices and the number of classes is not automatically inferred from data.
      """
      self.sigmoid = sigmoid
      self.reduction = reduction
      self.get_not_nans = get_not_nans
      self.include_background = (
          sigmoid if include_background is None else include_background
      )
      self.softmax = not sigmoid if softmax is None else softmax
      self.activate = activate
      self.ignore_empty = ignore_empty
      self.num_classes = num_classes
  
file_path: MONAI/monai/metrics/meandice.py
imports: from __future__ import annotations
  import torch
  from monai.metrics.utils import do_metric_reduction
  from monai.utils import MetricReduction
  from .metric import CumulativeIterationMetric
label_desc: Use image node_id 1 to create a new DiceHelper object  with example: obj = DiceHelper(include_background, sigmoid, softmax, activate, get_not_nans, reduction, ignore_empty, num_classes)