code: def run_inference_test(
      root_dir, model_file, device="cuda:0", amp=False, num_workers=4
  ):
      images = sorted(glob(os.path.join(root_dir, "im*.nii.gz")))
      segs = sorted(glob(os.path.join(root_dir, "seg*.nii.gz")))
      val_files = [
          {"image": img, "label": seg} for img, seg in zip(images, segs)
      ]
  
      # define transforms for image and segmentation
      val_transforms = Compose(
          [
              LoadImaged(keys=["image", "label"]),
              EnsureChannelFirstd(
                  keys=["image", "label"], channel_dim=-1
              ),
              ScaleIntensityd(keys=["image", "label"]),
          ]
      )
  
      # create a validation data loader
      val_ds = monai.data.Dataset(
          data=val_files, transform=val_transforms
      )
      val_loader = monai.data.DataLoader(
          val_ds, batch_size=1, num_workers=num_workers
      )
  
      # create UNet, DiceLoss and Adam optimizer
      net = monai.networks.nets.UNet(
          spatial_dims=3,
          in_channels=1,
          out_channels=1,
          channels=(16, 32, 64, 128, 256),
          strides=(2, 2, 2, 2),
          num_res_units=2,
      ).to(device)
  
      val_postprocessing = Compose(
          [
              Activationsd(keys="pred", sigmoid=True),
              AsDiscreted(keys="pred", threshold=0.5),
              KeepLargestConnectedComponentd(
                  keys="pred", applied_labels=[1]
              ),
              # test the case that `pred` in `engine.state.output`, while `image_meta_dict` in `engine.state.batch`
              SaveImaged(
                  keys="pred",
                  output_dir=root_dir,
                  output_postfix="seg_transform",
              ),
          ]
      )
      val_handlers = [
          StatsHandler(iteration_log=False),
          CheckpointLoader(
              load_path=f"{model_file}", load_dict={"net": net}
          ),
      ]
  
      saver = SaveImage(
          output_dir=root_dir, output_postfix="seg_handler"
      )
  
      def save_func(engine):
          for o in from_engine("pred")(engine.state.output):
              saver(o)
  
      evaluator = SupervisedEvaluator(
          device=device,
          val_data_loader=val_loader,
          network=net,
          inferer=SlidingWindowInferer(
              roi_size=(96, 96, 96), sw_batch_size=4, overlap=0.5
          ),
          postprocessing=val_postprocessing,
          key_val_metric={
              "val_mean_dice": MeanDice(
                  include_background=True,
                  output_transform=from_engine(["pred", "label"]),
              )
          },
          additional_metrics={
              "val_acc": Accuracy(
                  output_transform=from_engine(["pred", "label"])
              )
          },
          val_handlers=val_handlers,
          amp=bool(amp),
      )
      evaluator.add_event_handler(Events.ITERATION_COMPLETED, save_func)
      evaluator.run()
  
      return evaluator.state.best_metric
  
imports: from __future__ import annotations
  import os
  import shutil
  import tempfile
  import unittest
  import warnings
  from glob import glob
  import nibabel
  import numpy
  import torch
  from ignite.engine import Events
  from ignite.metrics import Accuracy
  import monai
  from monai.data import create_test_image_3d
  from monai.engines import IterationEvents, SupervisedEvaluator, SupervisedTrainer
  from monai.handlers import CheckpointLoader, CheckpointSaver, LrScheduleHandler, MeanDice, StatsHandler, TensorBoardImageHandler, TensorBoardStatsHandler, ValidationHandler, from_engine
  from monai.inferers import SimpleInferer, SlidingWindowInferer
  from monai.transforms import Activationsd, AsDiscreted, Compose, EnsureChannelFirstd, KeepLargestConnectedComponentd, LoadImaged, RandCropByPosNegLabeld, RandRotate90d, SaveImage, SaveImaged, ScaleIntensityd
  from monai.utils import optional_import, set_determinism
  from tests.testing_data.integration_answers import test_integration_value
  from tests.utils import DistTestCase, TimedCall, assert_allclose, pytorch_after, skip_if_quick
label_desc: Use image node_id 2 for calling a global function with example usage: run_inference_test(root_dir, model_file, device, amp, num_workers) and returns: evaluator