code: def predict_bbox_ir(
      cls_prob_buf,
      bbox_pred_buf,
      im_info_buf,
      out_buf,
      scales,
      ratios,
      feature_stride,
      rpn_min_size,
      iou_loss,
  ):
      """Predict bounding boxes based on anchors, scores and deltas.
  
      Parameters
      ----------
      cls_prob_buf : tvm.te.schedule.Buffer
          4-D with shape [batch, 2 * num_anchors, height, width]
  
      bbox_pred_buf : tvm.te.schedule.Buffer
          4-D with shape [batch, 4 * num_anchors, height, width]
  
      im_info_buf : tvm.te.schedule.Buffer
          2-D with shape [batch, 3]
  
      out_buf : tvm.te.schedule.Buffer
          3-D with shape [batch, num_bbox, 5]
          The last dimension is in format of [w_start, h_start, w_end, h_end, score]
  
      scales : list/tuple of float
          Scales of anchor windows.
  
      ratios : list/tuple of float
          Ratios of anchor windows.
  
      feature_stride : int
          The size of the receptive field each unit in the convolution layer of the rpn, for example
          the product of all stride's prior to this layer.
  
      rpn_min_size : int
          Minimum height or width in proposal.
  
      iou_loss : bool
          Usage of IoU loss.
  
      Returns
      -------
      stmt : Stmt
          The result IR statement.
      """
      batch, num_anchors, height, width = get_const_tuple(
          cls_prob_buf.shape
      )
      num_anchors //= 2
      ib = tvm.tir.ir_builder.create()
  
      p_score = ib.buffer_ptr(cls_prob_buf)
      p_delta = ib.buffer_ptr(bbox_pred_buf)
      p_im_info = ib.buffer_ptr(im_info_buf)
      p_out = ib.buffer_ptr(out_buf)
  
      idxm = tvm.tir.indexmod
      idxd = tvm.tir.indexdiv
  
      with ib.for_range(0, batch * height * width) as tid:
          w = idxm(tid, width)
          h = idxm(idxd(tid, width), height)
          b = idxd(idxd(tid, width), height)
  
          for k in range(num_anchors):
              out_index = tid * num_anchors + k
              ratio = ratios[k // len(scales)]
              scale = scales[k % len(scales)]
              anchor = generate_anchor(ratio, scale, feature_stride)
              im_height = p_im_info[b * 3]
              im_width = p_im_info[b * 3 + 1]
              x1 = anchor[0] + w * feature_stride
              y1 = anchor[1] + h * feature_stride
              x2 = anchor[2] + w * feature_stride
              y2 = anchor[3] + h * feature_stride
  
              delta = [
                  p_delta[
                      (
                          (((b * num_anchors + k) * 4 + i) * height + h)
                          * width
                          + w
                      )
                  ]
                  for i in range(4)
              ]
              regression_func = reg_iou if iou_loss else reg_bbox
              pred_x1, pred_y1, pred_x2, pred_y2 = regression_func(
                  x1, y1, x2, y2, *delta
              )
  
              pred_x1 = tvm.te.max(
                  tvm.te.min(pred_x1, im_width - 1.0), 0.0
              )
              pred_y1 = tvm.te.max(
                  tvm.te.min(pred_y1, im_height - 1.0), 0.0
              )
              pred_x2 = tvm.te.max(
                  tvm.te.min(pred_x2, im_width - 1.0), 0.0
              )
              pred_y2 = tvm.te.max(
                  tvm.te.min(pred_y2, im_height - 1.0), 0.0
              )
  
              real_height = (im_height / feature_stride).astype("int32")
              real_width = (im_width / feature_stride).astype("int32")
  
              bbox_w = pred_x2 - pred_x1 + 1.0
              bbox_h = pred_y2 - pred_y1 + 1.0
              min_size = p_im_info[b * 3 + 2] * rpn_min_size
  
              pred_score = p_score[
                  ((b * num_anchors * 2 + num_anchors + k) * height + h)
                  * width
                  + w
              ]
              pred_score = tvm.tir.Select(
                  tvm.tir.any(h >= real_height, w >= real_width),
                  -1.0,
                  pred_score,
              )
              p_out[out_index * 5 + 0] = pred_x1
              p_out[out_index * 5 + 1] = pred_y1
              p_out[out_index * 5 + 2] = pred_x2
              p_out[out_index * 5 + 3] = pred_y2
              p_out[out_index * 5 + 4] = pred_score
  
              with ib.if_scope(
                  tvm.tir.any(bbox_w < min_size, bbox_h < min_size)
              ):
                  p_out[out_index * 5 + 0] -= min_size / 2.0
                  p_out[out_index * 5 + 1] -= min_size / 2.0
                  p_out[out_index * 5 + 2] += min_size / 2.0
                  p_out[out_index * 5 + 3] += min_size / 2.0
                  p_out[out_index * 5 + 4] = -1.0
  
      return ib.get()
  
file_path: tvm/python/tvm/topi/vision/rcnn/proposal.py
imports: import math
  import tvm
  from tvm import te
  from ...utils import get_const_tuple, get_const_int
  from ...sort import argsort
label_desc: Use image node_id 4 for calling a global function with example usage: predict_bbox_ir(cls_prob_buf, bbox_pred_buf, im_info_buf, out_buf, scales, ratios, feature_stride, rpn_min_size, iou_loss) and returns: ib