code: def compute_recall_at_k(
      ground_truth_segments: List[Array],
      predicted_segments: List[Array],
      predicted_scores: List[Array],
      ranks: List[int],
      iou_thresholds: List[float],
  ) -> dict[str, Scalar]:
      """Compute recall at k given a iou threshold.
  
      Compute the recall@k for a set of ground-truth segments, predicted segments,
      and predicted scores, given a list of specific IoU threshold.
  
      Args:
        ground_truth_segments: Each element represents the ground-truth segment for
          the corresponding caption, with the start and end frame indices.
        predicted_segments: Each element represents the predicted segments for the
          corresponding caption, with the start and end frame indices for each.
        predicted_scores: Each element represents the predicted segments score
          for the corresponding caption.
        ranks: The number of top ranked segments to consider for each caption.
        iou_thresholds: The IoU threshold. A predicted segment is considered
          positive if its IoU with the ground-truth segment is at least this value.
  
      Returns:
        The mean recall@k over all captions with the given IoU.
      """
  
      metrics = {}
      num_captions = len(ground_truth_segments)
      for r in ranks:
          for iou_threshold in iou_thresholds:
              recall = 0.0
              for i in range(num_captions):
                  ground_truth_segment = ground_truth_segments[i]
                  predicted_segment_scores = predicted_scores[i]
                  num_predictions = min(
                      r, len(predicted_segment_scores)
                  )
                  if num_predictions == 0:
                      continue
                  sorted_indices = np.argsort(predicted_segment_scores)[
                      ::-1
                  ]
                  predicted_segments_sorted = predicted_segments[i][
                      sorted_indices
                  ]
                  for j in range(num_predictions):
                      predicted_segment = predicted_segments_sorted[j]
                      iou = compute_iou(
                          ground_truth_segment, predicted_segment
                      )
                      if iou >= iou_threshold:
                          recall += 1
                          break
              metrics.update(
                  {
                      "R@{},IOU={}".format(r, iou_threshold): recall
                      / num_captions
                  }
              )
      return metrics
  
file_path: scenic/scenic/projects/unloc/metrics.py
imports: from typing import Any, List, Union
  import jax.numpy
  import numpy
label_desc: Use image node_id 6 for calling a global function with example usage: compute_recall_at_k(ground_truth_segments, predicted_segments, predicted_scores, ranks, iou_thresholds) and returns: metrics