code: def fastrcnn_losses(labels, label_logits, fg_boxes, fg_box_logits):
      """
      Args:
          labels: n,
          label_logits: nxC
          fg_boxes: nfgx4, encoded
          fg_box_logits: nfgxCx4 or nfgx1x4 if class agnostic
  
      Returns:
          label_loss, box_loss
      """
      label_loss = tf.nn.sparse_softmax_cross_entropy_with_logits(
          labels=labels, logits=label_logits
      )
      label_loss = tf.reduce_mean(label_loss, name="label_loss")
  
      fg_inds = tf.where(labels > 0)[:, 0]
      fg_labels = tf.gather(labels, fg_inds)
      num_fg = tf.size(fg_inds, out_type=tf.int64)
      empty_fg = tf.equal(num_fg, 0)
      if int(fg_box_logits.shape[1]) > 1:
          fg_labels = tf.expand_dims(fg_labels, axis=1)  # nfg x 1
          fg_box_logits = tf.gather(
              fg_box_logits, fg_labels, batch_dims=1
          )
      fg_box_logits = tf.reshape(fg_box_logits, [-1, 4])  # nfg x 4
  
      with tf.name_scope("label_metrics"), tf.device("/cpu:0"):
          prediction = tf.argmax(
              label_logits, axis=1, name="label_prediction"
          )
          correct = tf.cast(
              tf.equal(prediction, labels), tf.float32
          )  # boolean/integer gather is unavailable on GPU
          accuracy = tf.reduce_mean(correct, name="accuracy")
          fg_label_pred = tf.argmax(
              tf.gather(label_logits, fg_inds), axis=1
          )
          num_zero = tf.reduce_sum(
              tf.cast(tf.equal(fg_label_pred, 0), tf.int64),
              name="num_zero",
          )
          false_negative = tf.where(
              empty_fg,
              0.0,
              tf.cast(tf.truediv(num_zero, num_fg), tf.float32),
              name="false_negative",
          )
          fg_accuracy = tf.where(
              empty_fg,
              0.0,
              tf.reduce_mean(tf.gather(correct, fg_inds)),
              name="fg_accuracy",
          )
  
      box_loss = tf.reduce_sum(tf.abs(fg_boxes - fg_box_logits))
      box_loss = tf.truediv(
          box_loss,
          tf.cast(tf.shape(labels)[0], tf.float32),
          name="box_loss",
      )
  
      add_moving_summary(
          label_loss,
          box_loss,
          accuracy,
          fg_accuracy,
          false_negative,
          tf.cast(num_fg, tf.float32, name="num_fg_label"),
      )
      return [label_loss, box_loss]
  
imports: import tensorflow
  from tensorpack import tfv1
  from tensorpack.models import Conv2D, FullyConnected, 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.utils.argtools import memoized_method
  from config import config
  from utils.box_ops import pairwise_iou
  from .model_box import decode_bbox_target, encode_bbox_target
  from .backbone import GroupNorm
label_desc: Use image node_id 4 for calling a global function with example usage: fastrcnn_losses(labels, label_logits, fg_boxes, fg_box_logits) and returns: list