code: def get_bboxes(self, det_bboxes, grid_pred, img_metas):
      # TODO: refactoring
      assert det_bboxes.shape[0] == grid_pred.shape[0]
      det_bboxes = det_bboxes.cpu()
      cls_scores = det_bboxes[:, [4]]
      det_bboxes = det_bboxes[:, :4]
      grid_pred = grid_pred.sigmoid().cpu()
  
      R, c, h, w = grid_pred.shape
      half_size = self.whole_map_size // 4 * 2
      assert h == w == half_size
      assert c == self.grid_points
  
      # find the point with max scores in the half-sized heatmap
      grid_pred = grid_pred.view(R * c, h * w)
      pred_scores, pred_position = grid_pred.max(dim=1)
      xs = pred_position % w
      ys = pred_position // w
  
      # get the position in the whole heatmap instead of half-sized heatmap
      for i in range(self.grid_points):
          xs[i :: self.grid_points] += self.sub_regions[i][0]
          ys[i :: self.grid_points] += self.sub_regions[i][1]
  
      # reshape to (num_rois, grid_points)
      pred_scores, xs, ys = tuple(
          map(lambda x: x.view(R, c), [pred_scores, xs, ys])
      )
  
      # get expanded pos_bboxes
      widths = (det_bboxes[:, 2] - det_bboxes[:, 0]).unsqueeze(-1)
      heights = (det_bboxes[:, 3] - det_bboxes[:, 1]).unsqueeze(-1)
      x1 = det_bboxes[:, 0, None] - widths / 2
      y1 = det_bboxes[:, 1, None] - heights / 2
      # map the grid point to the absolute coordinates
      abs_xs = (xs.float() + 0.5) / w * widths + x1
      abs_ys = (ys.float() + 0.5) / h * heights + y1
  
      # get the grid points indices that fall on the bbox boundaries
      x1_inds = [i for i in range(self.grid_size)]
      y1_inds = [i * self.grid_size for i in range(self.grid_size)]
      x2_inds = [
          self.grid_points - self.grid_size + i
          for i in range(self.grid_size)
      ]
      y2_inds = [
          (i + 1) * self.grid_size - 1 for i in range(self.grid_size)
      ]
  
      # voting of all grid points on some boundary
      bboxes_x1 = (abs_xs[:, x1_inds] * pred_scores[:, x1_inds]).sum(
          dim=1, keepdim=True
      ) / (pred_scores[:, x1_inds].sum(dim=1, keepdim=True))
      bboxes_y1 = (abs_ys[:, y1_inds] * pred_scores[:, y1_inds]).sum(
          dim=1, keepdim=True
      ) / (pred_scores[:, y1_inds].sum(dim=1, keepdim=True))
      bboxes_x2 = (abs_xs[:, x2_inds] * pred_scores[:, x2_inds]).sum(
          dim=1, keepdim=True
      ) / (pred_scores[:, x2_inds].sum(dim=1, keepdim=True))
      bboxes_y2 = (abs_ys[:, y2_inds] * pred_scores[:, y2_inds]).sum(
          dim=1, keepdim=True
      ) / (pred_scores[:, y2_inds].sum(dim=1, keepdim=True))
  
      bbox_res = torch.cat(
          [bboxes_x1, bboxes_y1, bboxes_x2, bboxes_y2, cls_scores],
          dim=1,
      )
      bbox_res[:, [0, 2]].clamp_(
          min=0, max=img_metas[0]["img_shape"][1]
      )
      bbox_res[:, [1, 3]].clamp_(
          min=0, max=img_metas[0]["img_shape"][0]
      )
  
      return bbox_res
  
file_path: insightface/detection/scrfd/mmdet/models/roi_heads/mask_heads/grid_head.py
imports: import numpy
  import torch
  import torch.nn
  import torch.nn.functional
  from mmcv.cnn import ConvModule, kaiming_init, normal_init
  from mmdet.models.builder import HEADS, build_loss
label_desc: Use image node_id 7 for calling the GridHead obj's underlying member method code with example usage: obj.get_bboxes(det_bboxes, grid_pred, img_metas) and returns: bbox_res