class_docstr: Metrics Configuration Callback.
docstr: Setup image and pixel-level AnomalibMetricsCollection within Anomalib Model.
  
  Args:
      trainer (pl.Trainer): PyTorch Lightning Trainer
      pl_module (AnomalyModule): Anomalib Model that inherits pl LightningModule.
      stage (str | None, optional): fit, validate, test or predict. Defaults to None.
docstr_tok: ["Setup","image","and","pixel-level","AnomalibMetricsCollection","within","Anomalib","Model",".","Args",":","trainer","(","pl.Trainer",")",":","PyTorch","Lightning","Trainer","pl_module","(","AnomalyModule",")",":","Anomalib","Model","that","inherits","pl","LightningModule",".","stage","(","str","|","None",",","optional",")",":","fit",",","validate",",","test","or","predict",".","Defaults","to","None","."]
code: def setup(
      self,
      trainer: pl.Trainer,
      pl_module: AnomalyModule,
      stage: str | None = None,
  ) -> None:
      """Setup image and pixel-level AnomalibMetricsCollection within Anomalib Model.
  
      Args:
          trainer (pl.Trainer): PyTorch Lightning Trainer
          pl_module (AnomalyModule): Anomalib Model that inherits pl LightningModule.
          stage (str | None, optional): fit, validate, test or predict. Defaults to None.
      """
      del trainer, stage  # These variables are not used.
  
      image_metric_names = (
          []
          if self.image_metric_names is None
          else self.image_metric_names
      )
  
      pixel_metric_names: list[str]
      if self.pixel_metric_names is None:
          pixel_metric_names = []
      elif self.task == TaskType.CLASSIFICATION:
          pixel_metric_names = []
          logger.warning(
              "Cannot perform pixel-level evaluation when task type is classification. "
              "Ignoring the following pixel-level metrics: %s",
              self.pixel_metric_names,
          )
      else:
          pixel_metric_names = self.pixel_metric_names
  
      if isinstance(pl_module, AnomalyModule):
          pl_module.image_metrics = create_metric_collection(
              image_metric_names, "image_"
          )
          if hasattr(pl_module, "pixel_metrics"):
              new_metrics = create_metric_collection(
                  pixel_metric_names, "pixel_"
              )
              for name in new_metrics.keys():
                  if name not in pl_module.pixel_metrics.keys():
                      pl_module.pixel_metrics.add_metrics(
                          new_metrics[name.split("_")[1]]
                      )
          else:
              pl_module.pixel_metrics = create_metric_collection(
                  pixel_metric_names, "pixel_"
              )
  
          pl_module.image_metrics.set_threshold(
              pl_module.image_threshold.value
          )
          pl_module.pixel_metrics.set_threshold(
              pl_module.pixel_threshold.value
          )
  
file_path: anomalib/src/anomalib/utils/callbacks/metrics_configuration.py
imports: from __future__ import annotations
  import logging
  import pytorch_lightning
  from pytorch_lightning.callbacks import Callback
  from anomalib.data import TaskType
  from anomalib.models.components.base.anomaly_module import AnomalyModule
  from anomalib.utils.metrics import create_metric_collection
label_desc: Use image node_id 2 for calling the MetricsConfigurationCallback obj's underlying member method code with example usage: obj.setup(trainer, pl_module, stage) without return types