code: def get_sampler(image_reader, patch_size, phase):
      if phase in ("training", "validation"):
          sampler = UniformSampler(
              image_reader, window_sizes=patch_size, windows_per_image=2
          )
      elif phase == "inference":
          sampler = GridSampler(
              image_reader,
              window_sizes=patch_size,
              window_border=(8, 8, 8),
              batch_size=1,
          )
      else:
          raise Exception(
              "Invalid phase choice: {}".format(
                  {"phase": ["train", "validation", "inference"]}
              )
          )
  
      return sampler
  
imports: import argparse
  import time
  import numpy
  import torch
  import torch.optim
  from libs import dataset_niftynet
  from libs import loss
  from libs import model
  from torch.utils.data import DataLoader
  from niftynet.engine.sampler_grid_v2 import GridSampler
  from niftynet.engine.sampler_uniform_v2 import UniformSampler
  from niftynet.engine.signal import TRAIN, VALID, INFER
  from niftynet.engine.windows_aggregator_grid import GridSamplesAggregator
  from niftynet.evaluation.pairwise_measures import PairwiseMeasures
  from niftynet.io.image_reader import ImageReader
  from niftynet.io.image_sets_partitioner import ImageSetsPartitioner
  from niftynet.layer.mean_variance_normalisation import MeanVarNormalisationLayer
  from niftynet.layer.pad import PadLayer
label_desc: Use image node_id 2 for calling a global function with example usage: get_sampler(image_reader, patch_size, phase) and returns: sampler