code: def metric_collection_from_names(
      metric_names: list[str], prefix: str | None
  ) -> AnomalibMetricCollection:
      """Create a metric collection from a list of metric names.
  
      The function will first try to retrieve the metric from the metrics defined in Anomalib metrics module,
      then in TorchMetrics package.
  
      Args:
          metric_names (list[str]): List of metric names to be included in the collection.
          prefix (str | None): prefix to assign to the metrics in the collection.
  
      Returns:
          AnomalibMetricCollection: Collection of metrics.
      """
      metrics_module = importlib.import_module("anomalib.utils.metrics")
      metrics = AnomalibMetricCollection([], prefix=prefix)
      for metric_name in metric_names:
          if hasattr(metrics_module, metric_name):
              metric_cls = getattr(metrics_module, metric_name)
              metrics.add_metrics(metric_cls())
          elif hasattr(torchmetrics, metric_name):
              try:
                  metric_cls = getattr(torchmetrics, metric_name)
                  metrics.add_metrics(metric_cls())
              except TypeError:
                  warnings.warn(
                      f"Incorrect constructor arguments for {metric_name} metric from TorchMetrics package."
                  )
          else:
              warnings.warn(
                  f"No metric with name {metric_name} found in Anomalib metrics or TorchMetrics."
              )
      return metrics
  
imports: from __future__ import annotations
  import importlib
  import warnings
  from typing import Any
  import torchmetrics
  from omegaconf import DictConfig, ListConfig
  from .anomaly_score_distribution import AnomalyScoreDistribution
  from .anomaly_score_threshold import AnomalyScoreThreshold
  from .aupr import AUPR
  from .aupro import AUPRO
  from .auroc import AUROC
  from .collection import AnomalibMetricCollection
  from .min_max import MinMax
  from .optimal_f1 import OptimalF1
  from .pro import PRO
label_desc: Use image node_id 1 for calling a global function with example usage: metric_collection_from_names(metric_names, prefix) and returns: metrics