code: def multilevel_rpn_losses(
      multilevel_anchors, multilevel_label_logits, multilevel_box_logits
  ):
      """
      Args:
          multilevel_anchors: #lvl RPNAnchors
          multilevel_label_logits: #lvl tensors of shape HxWxA
          multilevel_box_logits: #lvl tensors of shape HxWxAx4
  
      Returns:
          label_loss, box_loss
      """
      num_lvl = len(cfg.FPN.ANCHOR_STRIDES)
      assert len(multilevel_anchors) == num_lvl
      assert len(multilevel_label_logits) == num_lvl
      assert len(multilevel_box_logits) == num_lvl
  
      losses = []
      with tf.name_scope("rpn_losses"):
          for lvl in range(num_lvl):
              anchors = multilevel_anchors[lvl]
              label_loss, box_loss = rpn_losses(
                  anchors.gt_labels,
                  anchors.encoded_gt_boxes(),
                  multilevel_label_logits[lvl],
                  multilevel_box_logits[lvl],
                  name_scope="level{}".format(lvl + 2),
              )
              losses.extend([label_loss, box_loss])
  
          total_label_loss = tf.add_n(losses[::2], name="label_loss")
          total_box_loss = tf.add_n(losses[1::2], name="box_loss")
          add_moving_summary(total_label_loss, total_box_loss)
      return [total_label_loss, total_box_loss]
  
imports: import itertools
  import numpy
  import tensorflow
  from tensorpack import tfv1
  from tensorpack.models import Conv2D, FixedUnPooling, MaxPooling, layer_register
  from tensorpack.tfutils.argscope import argscope
  from tensorpack.tfutils.scope_utils import under_name_scope
  from tensorpack.tfutils.summary import add_moving_summary
  from tensorpack.tfutils.tower import get_current_tower_context
  from tensorpack.utils.argtools import memoized
  from config import config
  from utils.box_ops import area
  from .backbone import GroupNorm
  from .model_box import roi_align
  from .model_rpn import generate_rpn_proposals, rpn_losses, get_all_anchors
label_desc: Use image node_id 4 for calling a global function with example usage: multilevel_rpn_losses(multilevel_anchors, multilevel_label_logits, multilevel_box_logits) and returns: list