code: def model_load_test(
      config: Union[DictConfig, ListConfig],
      datamodule: LightningDataModule,
      results: Dict,
  ):
      """Create a new model based on the weights specified in config.
  
      Args:
          config ([Union[DictConfig, ListConfig]): Model config.
          datamodule (LightningDataModule): Dataloader
          results (Dict): Results from original model.
  
      """
      loaded_model = get_model(config)  # get new model
      # Assing the weight file to resume_from_checkpoint. When trainer is initialized, Trainer
      # object will automatically load the weights.
      config.trainer.resume_from_checkpoint = os.path.join(
          config.project.path, "weights/last.ckpt"
      )
  
      callbacks = get_callbacks(config)
  
      for index, callback in enumerate(callbacks):
          # Remove visualizer callback as saving results takes time
          if isinstance(callback, BaseVisualizerCallback):
              callbacks.pop(index)
              break
  
      # create new trainer object with LoadModel callback (assumes it is present)
      trainer = Trainer(callbacks=callbacks, **config.trainer)
      # Assumes the new model has LoadModel callback and the old one had ModelCheckpoint callback
      new_results = trainer.test(
          model=loaded_model, datamodule=datamodule
      )[0]
      assert np.isclose(
          results["image_AUROC"], new_results["image_AUROC"]
      ), f"Loaded model does not yield close performance results. {results['image_AUROC']} : {new_results['image_AUROC']}"
      if config.dataset.task == "segmentation":
          assert np.isclose(
              results["pixel_AUROC"], new_results["pixel_AUROC"]
          ), "Loaded model does not yield close performance results"
  
file_path: anomalib/tests/helpers/model.py
imports: import os
  from typing import Dict, List, Optional, Tuple, Union
  import numpy
  from omegaconf import DictConfig, ListConfig
  from pytorch_lightning import LightningDataModule, Trainer
  from pytorch_lightning.callbacks import ModelCheckpoint
  from anomalib.config import get_configurable_parameters, update_nncf_config
  from anomalib.data import TaskType, get_datamodule
  from anomalib.models import get_model
  from anomalib.models.components import AnomalyModule
  from anomalib.utils.callbacks import get_callbacks
  from anomalib.utils.callbacks.visualizer import BaseVisualizerCallback
label_desc: Use image node_id 2 for calling a global function with example usage: model_load_test(config, datamodule, results) without return types