code: def metric_collection_from_dicts(
      metrics: dict[str, dict[str, Any]], prefix: str | None
  ) -> AnomalibMetricCollection:
      """Create a metric collection from a dict of "metric name" -> "metric specifications".
  
      Example:
  
          metrics = {
              "PixelWiseF1Score": {
                  "class_path": "torchmetrics.F1Score",
                  "init_args": {},
              },
              "PixelWiseAUROC": {
                  "class_path": "anomalib.utils.metrics.AUROC",
                  "init_args": {
                      "compute_on_cpu": True,
                  },
              },
          }
  
      In the config file, the same specifications (for pixel-wise metrics) look like:
  
          ```yaml
          metrics:
              pixel:
                  PixelWiseF1Score:
                      class_path: torchmetrics.F1Score
                      init_args: {}
                  PixelWiseAUROC:
                      class_path: anomalib.utils.metrics.AUROC
                      init_args:
                          compute_on_cpu: true
          ```
  
      Args:
          metrics (dict[str, dict[str, Any]]): keys are metric names, values are dictionaries.
              Internal dict[str, Any] keys are "class_path" (value is string) and "init_args" (value is dict),
              following the convention in Pytorch Lightning CLI.
  
          prefix (str | None): prefix to assign to the metrics in the collection.
  
      Returns:
          AnomalibMetricCollection: Collection of metrics.
      """
      _validate_metrics_dict(metrics)
      metrics_collection = {}
      for name, dict_ in metrics.items():
          class_path = dict_["class_path"]
          kwargs = dict_["init_args"]
          cls = _get_class_from_path(class_path)
          metrics_collection[name] = cls(**kwargs)
      return AnomalibMetricCollection(metrics_collection, prefix=prefix)
  
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 4 for calling a global function with example usage: metric_collection_from_dicts(metrics, prefix) and returns: AnomalibMetricCollection