class_docstr: Region Proposal Network
  
  Args:
      anchor_generator (dict): configure of anchor generation
      rpn_target_assign (dict): configure of rpn targets assignment
      train_proposal (dict): configure of proposals generation
          at the stage of training
      test_proposal (dict): configure of proposals generation
          at the stage of prediction
      in_channel (int): channel of input feature maps which can be
          derived by from_config
class_docstr_tok: ["Region","Proposal","Network","Args",":","anchor_generator","(","dict",")",":","configure","of","anchor","generation","rpn_target_assign","(","dict",")",":","configure","of","rpn","targets","assignment","train_proposal","(","dict",")",":","configure","of","proposals","generation","at","the","stage","of","training","test_proposal","(","dict",")",":","configure","of","proposals","generation","at","the","stage","of","prediction","in_channel","(","int",")",":","channel","of","input","feature","maps","which","can","be","derived","by","from_config"]
docstr: scores (list[Tensor]): Multi-level scores prediction
  bbox_deltas (list[Tensor]): Multi-level deltas prediction
  anchors (list[Tensor]): Multi-level anchors
  inputs (dict): ground truth info
docstr_tok: ["scores","(","list","[","Tensor","]",")",":","Multi-level","scores","prediction","bbox_deltas","(","list","[","Tensor","]",")",":","Multi-level","deltas","prediction","anchors","(","list","[","Tensor","]",")",":","Multi-level","anchors","inputs","(","dict",")",":","ground","truth","info"]
code: def _gen_proposal(self, scores, bbox_deltas, anchors, inputs):
      """
      scores (list[Tensor]): Multi-level scores prediction
      bbox_deltas (list[Tensor]): Multi-level deltas prediction
      anchors (list[Tensor]): Multi-level anchors
      inputs (dict): ground truth info
      """
      prop_gen = (
          self.train_proposal if self.training else self.test_proposal
      )
      im_shape = inputs["im_shape"]
  
      # Collect multi-level proposals for each batch
      # Get 'topk' of them as final output
  
      if self.export_onnx:
          # bs = 1 when exporting onnx
          onnx_rpn_rois_list = []
          onnx_rpn_prob_list = []
          onnx_rpn_rois_num_list = []
  
          for rpn_score, rpn_delta, anchor in zip(
              scores, bbox_deltas, anchors
          ):
              (
                  onnx_rpn_rois,
                  onnx_rpn_rois_prob,
                  onnx_rpn_rois_num,
                  onnx_post_nms_top_n,
              ) = prop_gen(
                  scores=rpn_score[0:1],
                  bbox_deltas=rpn_delta[0:1],
                  anchors=anchor,
                  im_shape=im_shape[0:1],
              )
              onnx_rpn_rois_list.append(onnx_rpn_rois)
              onnx_rpn_prob_list.append(onnx_rpn_rois_prob)
              onnx_rpn_rois_num_list.append(onnx_rpn_rois_num)
  
          onnx_rpn_rois = paddle.concat(onnx_rpn_rois_list)
          onnx_rpn_prob = paddle.concat(onnx_rpn_prob_list).flatten()
  
          onnx_top_n = paddle.to_tensor(onnx_post_nms_top_n).cast(
              "int32"
          )
          onnx_num_rois = paddle.shape(onnx_rpn_prob)[0].cast("int32")
          k = paddle.minimum(onnx_top_n, onnx_num_rois)
          onnx_topk_prob, onnx_topk_inds = paddle.topk(onnx_rpn_prob, k)
          onnx_topk_rois = paddle.gather(onnx_rpn_rois, onnx_topk_inds)
          # TODO(wangguanzhong): Now bs_rois_collect in export_onnx is moved outside conditional branch
          # due to problems in dy2static of paddle. Will fix it when updating paddle framework.
          # bs_rois_collect = [onnx_topk_rois]
          # bs_rois_num_collect = paddle.shape(onnx_topk_rois)[0]
  
      else:
          bs_rois_collect = []
          bs_rois_num_collect = []
  
          batch_size = paddle.slice(
              paddle.shape(im_shape), [0], [0], [1]
          )
  
          # Generate proposals for each level and each batch.
          # Discard batch-computing to avoid sorting bbox cross different batches.
          for i in range(batch_size):
              rpn_rois_list = []
              rpn_prob_list = []
              rpn_rois_num_list = []
  
              for rpn_score, rpn_delta, anchor in zip(
                  scores, bbox_deltas, anchors
              ):
                  (
                      rpn_rois,
                      rpn_rois_prob,
                      rpn_rois_num,
                      post_nms_top_n,
                  ) = prop_gen(
                      scores=rpn_score[i : i + 1],
                      bbox_deltas=rpn_delta[i : i + 1],
                      anchors=anchor,
                      im_shape=im_shape[i : i + 1],
                  )
                  rpn_rois_list.append(rpn_rois)
                  rpn_prob_list.append(rpn_rois_prob)
                  rpn_rois_num_list.append(rpn_rois_num)
  
              if len(scores) > 1:
                  rpn_rois = paddle.concat(rpn_rois_list)
                  rpn_prob = paddle.concat(rpn_prob_list).flatten()
  
                  num_rois = paddle.shape(rpn_prob)[0].cast("int32")
                  if num_rois > post_nms_top_n:
                      topk_prob, topk_inds = paddle.topk(
                          rpn_prob, post_nms_top_n
                      )
                      topk_rois = paddle.gather(rpn_rois, topk_inds)
                  else:
                      topk_rois = rpn_rois
                      topk_prob = rpn_prob
              else:
                  topk_rois = rpn_rois_list[0]
                  topk_prob = rpn_prob_list[0].flatten()
  
              bs_rois_collect.append(topk_rois)
              bs_rois_num_collect.append(paddle.shape(topk_rois)[0:1])
  
          bs_rois_num_collect = paddle.concat(bs_rois_num_collect)
  
      if self.export_onnx:
          output_rois = [onnx_topk_rois]
          output_rois_num = paddle.shape(onnx_topk_rois)[0]
      else:
          output_rois = bs_rois_collect
          output_rois_num = bs_rois_num_collect
  
      return output_rois, output_rois_num
  
file_path: PaddleDetection/ppdet/modeling/proposal_generator/rpn_head.py
imports: import paddle
  import paddle.nn
  import paddle.nn.functional
  from paddle.nn.initializer import Normal
  from ppdet.core.workspace import register
  from .anchor_generator import AnchorGenerator
  from .target_layer import RPNTargetAssign
  from .proposal_generator import ProposalGenerator
  from ..cls_utils import _get_class_default_kwargs
label_desc: Use image node_id 4 for calling the RPNHead obj's underlying member method code with example usage: obj._gen_proposal(scores, bbox_deltas, anchors, inputs) and returns: output_rois,  output_rois_num