code: def inference(sampler, model, device, pred_path, cp_path):
      output = GridSamplesAggregator(
          image_reader=sampler.reader,
          window_border=(8, 8, 8),
          output_path=pred_path,
      )
      for _ in sampler():  # for each subject
          model.load_state_dict(torch.load(cp_path))
          model.to(device)
          model.eval()
  
          for batch_output in sampler():  # for each sliding window step
              window = batch_output["image"]
              # [...,0,:] eliminates time coordinate from NiftyNet Volume
              window = window[..., 0, :]
              window = np.transpose(window, (0, 4, 1, 2, 3))
              window = torch.Tensor(window).to(device)
  
              with torch.no_grad():
                  outputs = model(window)
  
              outputs = outputs.cpu().numpy()
              outputs = np.transpose(outputs, (0, 2, 3, 4, 1))
              output.decode_batch(
                  {"window_image": outputs.astype(np.float32)},
                  batch_output["image_location"],
              )
  
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 4 for calling a global function with example usage: inference(sampler, model, device, pred_path, cp_path) without return types