code: def heatmaps_to_keypoints(maps, rois):
      """Extract predicted keypoint locations from heatmaps. Output has shape
      (#rois, 4, #keypoints) with the 4 rows corresponding to (x, y, logit, prob)
      for each keypoint.
      """
      # This function converts a discrete image coordinate in a HEATMAP_SIZE x
      # HEATMAP_SIZE image to a continuous keypoint coordinate. We maintain
      # consistency with keypoints_to_heatmap_labels by using the conversion from
      # Heckbert 1990: c = d + 0.5, where d is a discrete coordinate and c is a
      # continuous coordinate.
      offset_x = rois[:, 0]
      offset_y = rois[:, 1]
  
      widths = rois[:, 2] - rois[:, 0]
      heights = rois[:, 3] - rois[:, 1]
      widths = widths.clamp(min=1)
      heights = heights.clamp(min=1)
      widths_ceil = widths.ceil()
      heights_ceil = heights.ceil()
  
      num_keypoints = maps.shape[1]
  
      if torchvision._is_tracing():
          xy_preds, end_scores = _onnx_heatmaps_to_keypoints_loop(
              maps,
              rois,
              widths_ceil,
              heights_ceil,
              widths,
              heights,
              offset_x,
              offset_y,
              torch.scalar_tensor(num_keypoints, dtype=torch.int64),
          )
          return xy_preds.permute(0, 2, 1), end_scores
  
      xy_preds = torch.zeros(
          (len(rois), 3, num_keypoints),
          dtype=torch.float32,
          device=maps.device,
      )
      end_scores = torch.zeros(
          (len(rois), num_keypoints),
          dtype=torch.float32,
          device=maps.device,
      )
      for i in range(len(rois)):
          roi_map_width = int(widths_ceil[i].item())
          roi_map_height = int(heights_ceil[i].item())
          width_correction = widths[i] / roi_map_width
          height_correction = heights[i] / roi_map_height
          roi_map = F.interpolate(
              maps[i][:, None],
              size=(roi_map_height, roi_map_width),
              mode="bicubic",
              align_corners=False,
          )[:, 0]
          # roi_map_probs = scores_to_probs(roi_map.copy())
          w = roi_map.shape[2]
          pos = roi_map.reshape(num_keypoints, -1).argmax(dim=1)
  
          x_int = pos % w
          y_int = torch.div(pos - x_int, w, rounding_mode="floor")
          # assert (roi_map_probs[k, y_int, x_int] ==
          #         roi_map_probs[k, :, :].max())
          x = (x_int.float() + 0.5) * width_correction
          y = (y_int.float() + 0.5) * height_correction
          xy_preds[i, 0, :] = x + offset_x[i]
          xy_preds[i, 1, :] = y + offset_y[i]
          xy_preds[i, 2, :] = 1
          end_scores[i, :] = roi_map[
              torch.arange(num_keypoints, device=roi_map.device),
              y_int,
              x_int,
          ]
  
      return xy_preds.permute(0, 2, 1), end_scores
  
imports: from typing import Dict, List, Optional, Tuple
  import torch
  import torch.nn.functional
  import torchvision
  from torch import nn, Tensor
  from torchvision.ops import boxes, roi_align
  from .None import _utils
label_desc: Use image node_id 8 for calling a global function with example usage: heatmaps_to_keypoints(maps, rois) and returns: xy_preds,  end_scores, xy_preds,  end_scores