code: def create_metric_collection(
      metrics: list[str] | dict[str, dict[str, Any]], prefix: str | None
  ) -> AnomalibMetricCollection:
      """Create a metric collection from a list of metric names or dictionaries.
  
      This function will dispatch the actual creation to the appropriate function depending on the input type:
  
          - if list[str] (names of metrics): see `metric_collection_from_names`
          - if dict[str, dict[str, Any]] (path and init args of a class): see `metric_collection_from_dicts`
  
      The function will first try to retrieve the metric from the metrics defined in Anomalib metrics module,
      then in TorchMetrics package.
  
      Args:
          metrics (list[str] | dict[str, dict[str, Any]]).
          prefix (str | None): prefix to assign to the metrics in the collection.
  
      Returns:
          AnomalibMetricCollection: Collection of metrics.
      """
      # fallback is using the names
  
      if isinstance(metrics, (ListConfig, list)):
          assert all(
              isinstance(metric, str) for metric in metrics
          ), f"All metrics must be strings, found {metrics}"
          return metric_collection_from_names(metrics, prefix)
  
      if isinstance(metrics, (DictConfig, dict)):
          _validate_metrics_dict(metrics)
          return metric_collection_from_dicts(metrics, prefix)
  
      raise ValueError(
          f"metrics must be a list or a dict, found {type(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 5 for calling a global function with example usage: create_metric_collection(metrics, prefix) and returns: metric_collection_from_names, metric_collection_from_dicts