code: def generate_proposal_target(
      rpn_rois,
      gt_classes,
      gt_boxes,
      batch_size_per_im,
      fg_fraction,
      fg_thresh,
      bg_thresh,
      num_classes,
      ignore_thresh=-1.0,
      is_crowd=None,
      use_random=True,
      is_cascade=False,
      cascade_iou=0.5,
      assign_on_cpu=False,
      add_gt_as_proposals=True,
  ):
      rois_with_gt = []
      tgt_labels = []
      tgt_bboxes = []
      tgt_gt_inds = []
      new_rois_num = []
  
      # In cascade rcnn, the threshold for foreground and background
      # is used from cascade_iou
      fg_thresh = cascade_iou if is_cascade else fg_thresh
      bg_thresh = cascade_iou if is_cascade else bg_thresh
      for i, rpn_roi in enumerate(rpn_rois):
          gt_bbox = gt_boxes[i]
          is_crowd_i = is_crowd[i] if is_crowd else None
          gt_class = paddle.squeeze(gt_classes[i], axis=-1)
  
          # Concat RoIs and gt boxes except cascade rcnn or none gt
          if add_gt_as_proposals and gt_bbox.shape[0] > 0:
              bbox = paddle.concat([rpn_roi, gt_bbox])
          else:
              bbox = rpn_roi
  
          # Step1: label bbox
          matches, match_labels = label_box(
              bbox,
              gt_bbox,
              fg_thresh,
              bg_thresh,
              False,
              ignore_thresh,
              is_crowd_i,
              assign_on_cpu,
          )
          # Step2: sample bbox
          sampled_inds, sampled_gt_classes = sample_bbox(
              matches,
              match_labels,
              gt_class,
              batch_size_per_im,
              fg_fraction,
              num_classes,
              use_random,
              is_cascade,
          )
  
          # Step3: make output
          rois_per_image = (
              bbox if is_cascade else paddle.gather(bbox, sampled_inds)
          )
          sampled_gt_ind = (
              matches
              if is_cascade
              else paddle.gather(matches, sampled_inds)
          )
          if gt_bbox.shape[0] > 0:
              sampled_bbox = paddle.gather(gt_bbox, sampled_gt_ind)
          else:
              num = rois_per_image.shape[0]
              sampled_bbox = paddle.zeros([num, 4], dtype="float32")
  
          rois_per_image.stop_gradient = True
          sampled_gt_ind.stop_gradient = True
          sampled_bbox.stop_gradient = True
          tgt_labels.append(sampled_gt_classes)
          tgt_bboxes.append(sampled_bbox)
          rois_with_gt.append(rois_per_image)
          tgt_gt_inds.append(sampled_gt_ind)
          new_rois_num.append(paddle.shape(sampled_inds)[0:1])
      new_rois_num = paddle.concat(new_rois_num)
      return (
          rois_with_gt,
          tgt_labels,
          tgt_bboxes,
          tgt_gt_inds,
          new_rois_num,
      )
  
file_path: PaddleDetection/ppdet/modeling/proposal_generator/target.py
imports: import numpy
  import paddle
  from ..bbox_utils import bbox2delta, bbox_overlaps
label_desc: Use image node_id 4 for calling a global function with example usage: generate_proposal_target(rpn_rois, gt_classes, gt_boxes, batch_size_per_im, fg_fraction, fg_thresh, bg_thresh, num_classes, ignore_thresh, is_crowd, use_random, is_cascade, cascade_iou, assign_on_cpu, add_gt_as_proposals) and returns: rois_with_gt,  tgt_labels,  tgt_bboxes,  tgt_gt_inds,  new_rois_num