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",")"]
code: def compute_channel(
      self, y_pred: torch.Tensor, y: torch.Tensor
  ) -> torch.Tensor:
      """"""
      y_o = torch.sum(y)
      if y_o > 0:
          return (2.0 * torch.sum(torch.masked_select(y, y_pred))) / (
              y_o + torch.sum(y_pred)
          )
      if self.ignore_empty:
          return torch.tensor(float("nan"), device=y_o.device)
      denorm = y_o + torch.sum(y_pred)
      if denorm <= 0:
          return torch.tensor(1.0, device=y_o.device)
      return torch.tensor(0.0, device=y_o.device)
  
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 2 for calling the DiceHelper obj's underlying member method code with example usage: obj.compute_channel(y_pred, y) and returns: torch, unknown, torch, torch