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: pred_scores (list[Tensor]): Multi-level scores prediction
  pred_deltas (list[Tensor]): Multi-level deltas prediction
  anchors (list[Tensor]): Multi-level anchors
  inputs (dict): ground truth info, including im, gt_bbox, gt_score
docstr_tok: ["pred_scores","(","list","[","Tensor","]",")",":","Multi-level","scores","prediction","pred_deltas","(","list","[","Tensor","]",")",":","Multi-level","deltas","prediction","anchors","(","list","[","Tensor","]",")",":","Multi-level","anchors","inputs","(","dict",")",":","ground","truth","info",",","including","im",",","gt_bbox",",","gt_score"]
code: def get_loss(self, pred_scores, pred_deltas, anchors, inputs):
      """
      pred_scores (list[Tensor]): Multi-level scores prediction
      pred_deltas (list[Tensor]): Multi-level deltas prediction
      anchors (list[Tensor]): Multi-level anchors
      inputs (dict): ground truth info, including im, gt_bbox, gt_score
      """
      anchors = [paddle.reshape(a, shape=(-1, 4)) for a in anchors]
      anchors = paddle.concat(anchors)
  
      scores = [
          paddle.reshape(
              paddle.transpose(v, perm=[0, 2, 3, 1]),
              shape=(v.shape[0], -1, 1),
          )
          for v in pred_scores
      ]
      scores = paddle.concat(scores, axis=1)
  
      deltas = [
          paddle.reshape(
              paddle.transpose(v, perm=[0, 2, 3, 1]),
              shape=(v.shape[0], -1, 4),
          )
          for v in pred_deltas
      ]
      deltas = paddle.concat(deltas, axis=1)
  
      score_tgt, bbox_tgt, loc_tgt, norm = self.rpn_target_assign(
          inputs, anchors
      )
  
      scores = paddle.reshape(x=scores, shape=(-1,))
      deltas = paddle.reshape(x=deltas, shape=(-1, 4))
  
      score_tgt = paddle.concat(score_tgt)
      score_tgt.stop_gradient = True
  
      pos_mask = score_tgt == 1
      pos_ind = paddle.nonzero(pos_mask)
  
      valid_mask = score_tgt >= 0
      valid_ind = paddle.nonzero(valid_mask)
  
      # cls loss
      if valid_ind.shape[0] == 0:
          loss_rpn_cls = paddle.zeros([1], dtype="float32")
      else:
          score_pred = paddle.gather(scores, valid_ind)
          score_label = paddle.gather(score_tgt, valid_ind).cast(
              "float32"
          )
          score_label.stop_gradient = True
          loss_rpn_cls = F.binary_cross_entropy_with_logits(
              logit=score_pred, label=score_label, reduction="sum"
          )
  
      # reg loss
      if pos_ind.shape[0] == 0:
          loss_rpn_reg = paddle.zeros([1], dtype="float32")
      else:
          loc_pred = paddle.gather(deltas, pos_ind)
          loc_tgt = paddle.concat(loc_tgt)
          loc_tgt = paddle.gather(loc_tgt, pos_ind)
          loc_tgt.stop_gradient = True
  
          if self.loss_rpn_bbox is None:
              loss_rpn_reg = paddle.abs(loc_pred - loc_tgt).sum()
          else:
              loss_rpn_reg = self.loss_rpn_bbox(loc_pred, loc_tgt).sum()
  
      return {
          "loss_rpn_cls": loss_rpn_cls / norm,
          "loss_rpn_reg": loss_rpn_reg / norm,
      }
  
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 5 for calling the RPNHead obj's underlying member method code with example usage: obj.get_loss(pred_scores, pred_deltas, anchors, inputs) and returns: dict