code: def seg_eval(pred, label, clss):
      """
      calculate the dice between prediction and ground truth
      input:
          pred: predicted mask
          label: groud truth
          clss: eg. [0, 1] for binary class
      """
      Ncls = len(clss)
      dices = np.zeros(Ncls)
      [depth, height, width] = pred.shape
      for idx, cls in enumerate(clss):
          # binary map
          pred_cls = np.zeros([depth, height, width])
          pred_cls[np.where(pred == cls)] = 1
          label_cls = np.zeros([depth, height, width])
          label_cls[np.where(label == cls)] = 1
  
          # cal the inter & conv
          s = pred_cls + label_cls
          inter = len(np.where(s >= 2)[0])
          conv = len(np.where(s >= 1)[0]) + inter
          try:
              dice = 2.0 * inter / conv
          except:
              print("conv is zeros when dice = 2.0 * inter / conv")
              dice = -1
  
          dices[idx] = dice
  
      return dices
  
file_path: MedicalNet/test.py
imports: from setting import parse_opts
  from datasets.brains18 import BrainS18Dataset
  from model import generate_model
  import torch
  import numpy
  from torch.utils.data import DataLoader
  import torch.nn.functional
  from scipy import ndimage
  import nibabel
  import sys
  import os
  from utils.file_process import load_lines
  import numpy
label_desc: Use image node_id 1 for calling a global function with example usage: seg_eval(pred, label, clss) and returns: dices