code: def rpn(self, image, features, inputs):
      assert len(cfg.RPN.ANCHOR_SIZES) == len(cfg.FPN.ANCHOR_STRIDES)
  
      image_shape2d = tf.shape(image)[2:]  # h,w
      all_anchors_fpn = get_all_anchors_fpn(
          strides=cfg.FPN.ANCHOR_STRIDES,
          sizes=cfg.RPN.ANCHOR_SIZES,
          ratios=cfg.RPN.ANCHOR_RATIOS,
          max_size=cfg.PREPROC.MAX_SIZE,
      )
      multilevel_anchors = [
          RPNAnchors(
              all_anchors_fpn[i],
              inputs["anchor_labels_lvl{}".format(i + 2)],
              inputs["anchor_boxes_lvl{}".format(i + 2)],
          )
          for i in range(len(all_anchors_fpn))
      ]
      self.slice_feature_and_anchors(features, multilevel_anchors)
  
      # Multi-Level RPN Proposals
      rpn_outputs = [
          rpn_head(
              "rpn", pi, cfg.FPN.NUM_CHANNEL, len(cfg.RPN.ANCHOR_RATIOS)
          )
          for pi in features
      ]
      multilevel_label_logits = [k[0] for k in rpn_outputs]
      multilevel_box_logits = [k[1] for k in rpn_outputs]
      multilevel_pred_boxes = [
          anchor.decode_logits(logits)
          for anchor, logits in zip(
              multilevel_anchors, multilevel_box_logits
          )
      ]
  
      proposal_boxes, proposal_scores = generate_fpn_proposals(
          multilevel_pred_boxes, multilevel_label_logits, image_shape2d
      )
  
      if self.training:
          losses = multilevel_rpn_losses(
              multilevel_anchors,
              multilevel_label_logits,
              multilevel_box_logits,
          )
      else:
          losses = []
  
      return BoxProposals(proposal_boxes), losses
  
imports: from tensorpack import tfv1
  from tensorpack import ModelDesc
  from tensorpack.models import GlobalAvgPooling, l2_regularizer, regularize_cost
  from tensorpack.tfutils import optimizer
  from tensorpack.tfutils.summary import add_moving_summary
  from config import config
  from data import get_all_anchors, get_all_anchors_fpn
  from utils.box_ops import area
  from .None import model_frcnn
  from .None import model_mrcnn
  from .backbone import image_preprocess, resnet_c4_backbone, resnet_conv5, resnet_fpn_backbone
  from .model_box import RPNAnchors, clip_boxes, crop_and_resize, roi_align
  from .model_cascade import CascadeRCNNHead
  from .model_fpn import fpn_model, generate_fpn_proposals, multilevel_roi_align, multilevel_rpn_losses
  from .model_frcnn import BoxProposals, FastRCNNHead, fastrcnn_outputs, fastrcnn_predictions, sample_fast_rcnn_targets
  from .model_mrcnn import maskrcnn_loss, maskrcnn_upXconv_head, unpackbits_masks
  from .model_rpn import generate_rpn_proposals, rpn_head, rpn_losses
label_desc: Use image node_id 4 for calling the ResNetFPNModel obj's underlying member method code with example usage: obj.rpn(image, features, inputs) and returns: BoxProposals,  losses