code: def run_inference_test(
      root_dir, test_x, test_y, device="cuda:0", num_workers=10
  ):
      # define transforms for image and classification
      val_transforms = Compose(
          [
              LoadImage(image_only=True),
              EnsureChannelFirst(channel_dim="no_channel"),
              ScaleIntensity(),
          ]
      )
      val_ds = MedNISTDataset(test_x, test_y, val_transforms)
      val_loader = DataLoader(
          val_ds, batch_size=300, num_workers=num_workers
      )
  
      model = DenseNet121(
          spatial_dims=2,
          in_channels=1,
          out_channels=len(np.unique(test_y)),
      ).to(device)
  
      model_filename = os.path.join(root_dir, "best_metric_model.pth")
      model.load_state_dict(torch.load(model_filename))
      y_true = []
      y_pred = []
      with eval_mode(model):
          for test_data in val_loader:
              test_images, test_labels = test_data[0].to(
                  device
              ), test_data[1].to(device)
              pred = model(test_images).argmax(dim=1)
              for i in range(len(pred)):
                  y_true.append(test_labels[i].item())
                  y_pred.append(pred[i].item())
      tps = [
          np.sum(
              (np.asarray(y_true) == idx) & (np.asarray(y_pred) == idx)
          )
          for idx in np.unique(test_y)
      ]
      return tps
  
imports: from __future__ import annotations
  import os
  import unittest
  import warnings
  import numpy
  import torch
  from torch.utils.data import DataLoader
  import monai
  from monai.apps import download_and_extract
  from monai.data import decollate_batch
  from monai.metrics import ROCAUCMetric
  from monai.networks import eval_mode
  from monai.networks.nets import DenseNet121
  from monai.transforms import Activations, AsDiscrete, Compose, EnsureChannelFirst, LoadImage, RandFlip, RandRotate, RandZoom, ScaleIntensity, Transpose
  from monai.utils import set_determinism
  from tests.testing_data.integration_answers import test_integration_value
  from tests.utils import DistTestCase, TimedCall, skip_if_downloading_fails, skip_if_quick, testing_data_config
label_desc: Use image node_id 2 for calling a global function with example usage: run_inference_test(root_dir, test_x, test_y, device, num_workers) and returns: tps