code: def compute_dice(
      y_pred: torch.Tensor,
      y: torch.Tensor,
      include_background: bool = True,
      ignore_empty: bool = True,
      num_classes: int | None = None,
  ) -> torch.Tensor:
      """Computes Dice score metric for a batch of predictions.
  
      Args:
          y_pred: input data to compute, typical segmentation model output.
              `y_pred` can be single-channel class indices or in the one-hot format.
          y: ground truth to compute mean dice metric. `y` can be single-channel class indices or in the one-hot format.
          include_background: whether to include Dice computation on the first channel of
              the predicted output. Defaults to True.
          ignore_empty: whether to ignore empty ground truth cases during calculation.
              If `True`, NaN value will be set for empty ground truth cases.
              If `False`, 1 will be set if the predictions of empty ground truth cases are also 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.
  
      Returns:
          Dice scores per batch and per class, (shape: [batch_size, num_classes]).
  
      """
      return DiceHelper(  # type: ignore
          include_background=include_background,
          reduction=MetricReduction.NONE,
          get_not_nans=False,
          softmax=False,
          ignore_empty=ignore_empty,
          num_classes=num_classes,
      )(y_pred=y_pred, y=y)
  
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 for calling a global function with example usage: compute_dice(y_pred, y, include_background, ignore_empty, num_classes) and returns: DiceHelper