code: def get_dice_per_batch_and_class(pred, y, n_classes):
      """
      computes dice scores per batch instance and class.
      :param pred: prediction array of shape (b, 1, y, x, (z)) (e.g. softmax prediction with argmax over dim 1)
      :param y: ground truth array of shape (b, 1, y, x, (z)) (contains int [0, ..., n_classes]
      :param n_classes: int
      :return: dice scores of shape (b, c)
      """
      pred = get_one_hot_encoding(pred, n_classes)
      y = get_one_hot_encoding(y, n_classes)
      axes = tuple(range(2, len(pred.shape)))
      intersect = np.sum(pred * y, axis=axes)
      denominator = (
          np.sum(pred, axis=axes) + np.sum(y, axis=axes) + 1e-8
      )
      dice = 2.0 * intersect / denominator
      return dice
  
imports: import numpy
  import scipy.misc
  import scipy.ndimage
  import torch
  from torch.autograd import Variable
  import torch.nn
label_desc: Use image node_id 25 for calling a global function with example usage: get_dice_per_batch_and_class(pred, y, n_classes) and returns: dice