class_docstr: Run Model on all categories.
docstr: Tests the model metrics but also acts as a setup.
docstr_tok: ["Tests","the","model","metrics","but","also","acts","as","a","setup","."]
code: def _test_metrics(self, trainer, config, model, datamodule):
      """Tests the model metrics but also acts as a setup."""
  
      results = trainer.test(model=model, datamodule=datamodule)[0]
  
      thresholds = OmegaConf.load(
          "tests/nightly/models/performance_thresholds.yaml"
      )
  
      threshold = thresholds[config.model.name][config.dataset.category]
      if (
          "optimization" in config.keys()
          and "nncf" in config.optimization.keys()
          and config.optimization.nncf.apply
      ):
          threshold = threshold.nncf
      if not (
          np.isclose(
              results["image_AUROC"],
              threshold["image_AUROC"],
              rtol=0.05,
          )
          or (results["image_AUROC"] >= threshold["image_AUROC"])
      ):
          raise AssertionError(
              f"results['image_AUROC']: {results['image_AUROC']} >= "
              f"threshold['image_AUROC']: {threshold['image_AUROC']}"
          )
  
      if config.dataset.task == "segmentation":
          if not (
              np.isclose(
                  results["pixel_AUROC"],
                  threshold["pixel_AUROC"],
                  rtol=0.05,
              )
              or (results["pixel_AUROC"] >= threshold["pixel_AUROC"])
          ):
              raise AssertionError(
                  f"results['pixel_AUROC']:{results['pixel_AUROC']} >= "
                  f"threshold['pixel_AUROC']:{threshold['pixel_AUROC']}"
              )
      return results
  
imports: import itertools
  import math
  import multiprocessing
  import random
  import tempfile
  from concurrent.futures import ProcessPoolExecutor
  from datetime import datetime
  from pathlib import Path
  from typing import Dict, List, Union
  import numpy
  import pandas
  import torch
  from omegaconf import DictConfig, ListConfig, OmegaConf
  from pytorch_lightning import seed_everything
  from anomalib.utils.sweep.config import flatten_sweep_params
  from tests.helpers.dataset import get_dataset_path
  from tests.helpers.model import model_load_test, setup_model_train
label_desc: Use image node_id 1 for calling the TestModel obj's underlying member method code with example usage: obj._test_metrics(trainer, config, model, datamodule) and returns: results