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:
      y_pred: input predictions with shape (batch_size, num_classes or 1, spatial_dims...).
          the number of channels is inferred from ``y_pred.shape[1]`` when ``num_classes is None``.
      y: ground truth with shape (batch_size, num_classes or 1, spatial_dims...).
docstr_tok: ["Args",":","y_pred",":","input","predictions","with","shape","(","batch_size",",","num_classes","or","1",",","spatial_dims","...",")",".","the","number","of","channels","is","inferred","from","``","y_pred.shape","[","1","]","``","when","``","num_classes","is","None","``",".","y",":","ground","truth","with","shape","(","batch_size",",","num_classes","or","1",",","spatial_dims","...",")","."]
code: def __call__(
      self, y_pred: torch.Tensor, y: torch.Tensor
  ) -> torch.Tensor | tuple[torch.Tensor, torch.Tensor]:
      """
  
      Args:
          y_pred: input predictions with shape (batch_size, num_classes or 1, spatial_dims...).
              the number of channels is inferred from ``y_pred.shape[1]`` when ``num_classes is None``.
          y: ground truth with shape (batch_size, num_classes or 1, spatial_dims...).
      """
      _softmax, _sigmoid = self.softmax, self.sigmoid
      if self.num_classes is None:
          n_pred_ch = y_pred.shape[
              1
          ]  # y_pred is in one-hot format or multi-channel scores
      else:
          n_pred_ch = self.num_classes
          if (
              y_pred.shape[1] == 1 and self.num_classes > 1
          ):  # y_pred is single-channel class indices
              _softmax = _sigmoid = False
  
      if _softmax:
          if n_pred_ch > 1:
              y_pred = torch.argmax(y_pred, dim=1, keepdim=True)
  
      elif _sigmoid:
          if self.activate:
              y_pred = torch.sigmoid(y_pred)
          y_pred = y_pred > 0.5
  
      first_ch = 0 if self.include_background else 1
      data = []
      for b in range(y_pred.shape[0]):
          c_list = []
          for c in range(first_ch, n_pred_ch) if n_pred_ch > 1 else [1]:
              x_pred = (
                  (y_pred[b, 0] == c)
                  if (y_pred.shape[1] == 1)
                  else y_pred[b, c].bool()
              )
              x = (y[b, 0] == c) if (y.shape[1] == 1) else y[b, c]
              c_list.append(self.compute_channel(x_pred, x))
          data.append(torch.stack(c_list))
      data = torch.stack(data, dim=0).contiguous()  # type: ignore
  
      f, not_nans = do_metric_reduction(data, self.reduction)  # type: ignore
      return (f, not_nans) if self.get_not_nans else f
  
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 3 for calling the DiceHelper obj's underlying member method code with example usage: obj.__call__(y_pred, y) and returns: unknown