code: def bucket2bbox(
      proposals,
      cls_preds,
      offset_preds,
      num_buckets,
      scale_factor=1.0,
      max_shape=None,
      clip_border=True,
  ):
      """Apply bucketing estimation (cls preds) and fine regression (offset
      preds) to generate det bboxes.
  
      Args:
          proposals (Tensor): Boxes to be transformed. Shape (n, 4)
          cls_preds (Tensor): bucketing estimation. Shape (n, num_buckets*2).
          offset_preds (Tensor): fine regression. Shape (n, num_buckets*2).
          num_buckets (int): Number of buckets.
          scale_factor (float): Scale factor to rescale proposals.
          max_shape (tuple[int, int]): Maximum bounds for boxes. specifies (H, W)
          clip_border (bool, optional): Whether clip the objects outside the
              border of the image. Defaults to True.
  
      Returns:
          tuple[Tensor]: (bboxes, loc_confidence).
  
              - bboxes: predicted bboxes. Shape (n, 4)
              - loc_confidence: localization confidence of predicted bboxes.
                  Shape (n,).
      """
  
      side_num = int(np.ceil(num_buckets / 2.0))
      cls_preds = cls_preds.view(-1, side_num)
      offset_preds = offset_preds.view(-1, side_num)
  
      scores = F.softmax(cls_preds, dim=1)
      score_topk, score_label = scores.topk(
          2, dim=1, largest=True, sorted=True
      )
  
      rescaled_proposals = bbox_rescale(proposals, scale_factor)
  
      pw = rescaled_proposals[..., 2] - rescaled_proposals[..., 0]
      ph = rescaled_proposals[..., 3] - rescaled_proposals[..., 1]
      px1 = rescaled_proposals[..., 0]
      py1 = rescaled_proposals[..., 1]
      px2 = rescaled_proposals[..., 2]
      py2 = rescaled_proposals[..., 3]
  
      bucket_w = pw / num_buckets
      bucket_h = ph / num_buckets
  
      score_inds_l = score_label[0::4, 0]
      score_inds_r = score_label[1::4, 0]
      score_inds_t = score_label[2::4, 0]
      score_inds_d = score_label[3::4, 0]
      l_buckets = px1 + (0.5 + score_inds_l.float()) * bucket_w
      r_buckets = px2 - (0.5 + score_inds_r.float()) * bucket_w
      t_buckets = py1 + (0.5 + score_inds_t.float()) * bucket_h
      d_buckets = py2 - (0.5 + score_inds_d.float()) * bucket_h
  
      offsets = offset_preds.view(-1, 4, side_num)
      inds = torch.arange(proposals.size(0)).to(proposals).long()
      l_offsets = offsets[:, 0, :][inds, score_inds_l]
      r_offsets = offsets[:, 1, :][inds, score_inds_r]
      t_offsets = offsets[:, 2, :][inds, score_inds_t]
      d_offsets = offsets[:, 3, :][inds, score_inds_d]
  
      x1 = l_buckets - l_offsets * bucket_w
      x2 = r_buckets - r_offsets * bucket_w
      y1 = t_buckets - t_offsets * bucket_h
      y2 = d_buckets - d_offsets * bucket_h
  
      if clip_border and max_shape is not None:
          x1 = x1.clamp(min=0, max=max_shape[1] - 1)
          y1 = y1.clamp(min=0, max=max_shape[0] - 1)
          x2 = x2.clamp(min=0, max=max_shape[1] - 1)
          y2 = y2.clamp(min=0, max=max_shape[0] - 1)
      bboxes = torch.cat(
          [x1[:, None], y1[:, None], x2[:, None], y2[:, None]], dim=-1
      )
  
      # bucketing guided rescoring
      loc_confidence = score_topk[:, 0]
      top2_neighbor_inds = (
          score_label[:, 0] - score_label[:, 1]
      ).abs() == 1
      loc_confidence += score_topk[:, 1] * top2_neighbor_inds.float()
      loc_confidence = loc_confidence.view(-1, 4).mean(dim=1)
  
      return bboxes, loc_confidence
  
file_path: insightface/detection/scrfd/mmdet/core/bbox/coder/bucketing_bbox_coder.py
imports: import numpy
  import torch
  import torch.nn.functional
  from ..builder import BBOX_CODERS
  from ..transforms import bbox_rescale
  from .base_bbox_coder import BaseBBoxCoder
label_desc: Use image node_id 3 for calling a global function with example usage: bucket2bbox(proposals, cls_preds, offset_preds, num_buckets, scale_factor, max_shape, clip_border) and returns: bboxes,  loc_confidence