code: def pro_score(
      predictions: Tensor, comps: Tensor, threshold: float = 0.5
  ) -> Tensor:
      """Calculate the PRO score for a batch of predictions.
  
      Args:
          predictions (Tensor): Predicted anomaly masks (Bx1xHxW)
          comps: (Tensor): Labeled connected components (BxHxW). The components should be labeled from 0 to N
          threshold (float): When predictions are passed as float, the threshold is used to binarize the predictions.
  
      Returns:
          Tensor: Scalar value representing the average PRO score for the input batch.
      """
      if predictions.dtype == torch.float:
          predictions = predictions > threshold
  
      n_comps = len(comps.unique())
  
      preds = comps.clone()
      # match the shapes in case one of the tensors is N1HW
      preds = preds.reshape(predictions.shape)
      preds[~predictions] = 0
      if n_comps == 1:  # only background
          return torch.Tensor([1.0])
      pro = recall(
          preds.flatten(),
          comps.flatten(),
          num_classes=n_comps,
          average="macro",
          ignore_index=0,
      )
      return pro
  
file_path: anomalib/src/anomalib/utils/metrics/pro.py
imports: from __future__ import annotations
  import torch
  from torch import Tensor
  from torchmetrics import Metric
  from torchmetrics.functional import recall
  from torchmetrics.utilities.data import dim_zero_cat
  from anomalib.utils.cv import connected_components_cpu, connected_components_gpu
label_desc: Use image node_id 1 for calling a global function with example usage: pro_score(predictions, comps, threshold) and returns: pro, torch