code: def per_sample_dice(
      predictions, labels, threshold: float = 0.5, smooth: float = 1e-3
  ):
      """Calculate Dice score per sample."""
      score = np.empty(len(labels))
      for i in range(len(labels)):
          gt_onehot, pred_onehot = format_segmentation_masks(
              labels[i], predictions[i], threshold
          )
          tp_count, gt_count, pred_count = segmentation_counts_micro(
              gt_onehot, pred_onehot
          )
          score[i] = (2 * tp_count + smooth) / (
              gt_count + pred_count + smooth
          )
      return score.tolist()
  
file_path: deepchecks/deepchecks/vision/metrics_utils/semantic_segmentation_metrics.py
imports: from collections import defaultdict
  from typing import Tuple
  import numpy
  import torch
  from ignite.metrics import Metric
  from deepchecks.core.errors import DeepchecksValueError
  from deepchecks.vision.metrics_utils.semantic_segmentation_metric_utils import format_segmentation_masks, segmentation_counts_micro, segmentation_counts_per_class
label_desc: Use image node_id 1 for calling a global function with example usage: per_sample_dice(predictions, labels, threshold, smooth) and returns: score