code: def test(data_loader, model, img_names, sets):
      masks = []
      model.eval()  # for testing
      for batch_id, batch_data in enumerate(data_loader):
          # forward
          volume = batch_data
          if not sets.no_cuda:
              volume = volume.cuda()
          with torch.no_grad():
              probs = model(volume)
              probs = F.softmax(probs, dim=1)
  
          # resize mask to original size
          [batchsize, _, mask_d, mask_h, mask_w] = probs.shape
          data = nib.load(
              os.path.join(sets.data_root, img_names[batch_id])
          )
          data = data.get_data()
          [depth, height, width] = data.shape
          mask = probs[0]
          scale = [
              1,
              depth * 1.0 / mask_d,
              height * 1.0 / mask_h,
              width * 1.0 / mask_w,
          ]
          mask = ndimage.interpolation.zoom(mask, scale, order=1)
          mask = np.argmax(mask, axis=0)
  
          masks.append(mask)
  
      return masks
  
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 2 for calling a global function with example usage: test(data_loader, model, img_names, sets) and returns: masks