code: def forward_backward(self, x):
      data, label, rpn_cls_targets, rpn_box_targets, rpn_box_masks = x
      with autograd.record():
          gt_label = label[:, :, 4:5]
          gt_box = label[:, :, :4]
          (
              cls_pred,
              box_pred,
              roi,
              samples,
              matches,
              rpn_score,
              rpn_box,
              anchors,
              cls_targets,
              box_targets,
              box_masks,
              _,
          ) = net(data, gt_box, gt_label)
          # losses of rpn
          rpn_score = rpn_score.squeeze(axis=-1)
          num_rpn_pos = (rpn_cls_targets >= 0).sum()
          rpn_loss1 = (
              self.rpn_cls_loss(
                  rpn_score, rpn_cls_targets, rpn_cls_targets >= 0
              )
              * rpn_cls_targets.size
              / num_rpn_pos
          )
          rpn_loss2 = (
              self.rpn_box_loss(rpn_box, rpn_box_targets, rpn_box_masks)
              * rpn_box.size
              / num_rpn_pos
          )
          # rpn overall loss, use sum rather than average
          rpn_loss = rpn_loss1 + rpn_loss2
          # losses of rcnn
          num_rcnn_pos = (cls_targets >= 0).sum()
          rcnn_loss1 = (
              self.rcnn_cls_loss(
                  cls_pred,
                  cls_targets,
                  cls_targets.expand_dims(-1) >= 0,
              )
              * cls_targets.size
              / num_rcnn_pos
          )
          rcnn_loss2 = (
              self.rcnn_box_loss(box_pred, box_targets, box_masks)
              * box_pred.size
              / num_rcnn_pos
          )
          rcnn_loss = rcnn_loss1 + rcnn_loss2
          # overall losses
          total_loss = (
              rpn_loss.sum() * self.mix_ratio
              + rcnn_loss.sum() * self.mix_ratio
          )
  
          rpn_loss1_metric = rpn_loss1.mean() * self.mix_ratio
          rpn_loss2_metric = rpn_loss2.mean() * self.mix_ratio
          rcnn_loss1_metric = rcnn_loss1.mean() * self.mix_ratio
          rcnn_loss2_metric = rcnn_loss2.mean() * self.mix_ratio
          rpn_acc_metric = [
              [rpn_cls_targets, rpn_cls_targets >= 0],
              [rpn_score],
          ]
          rpn_l1_loss_metric = [
              [rpn_box_targets, rpn_box_masks],
              [rpn_box],
          ]
          rcnn_acc_metric = [[cls_targets], [cls_pred]]
          rcnn_l1_loss_metric = [[box_targets, box_masks], [box_pred]]
  
          if args.amp:
              with amp.scale_loss(
                  total_loss, self._optimizer
              ) as scaled_losses:
                  autograd.backward(scaled_losses)
          else:
              total_loss.backward()
  
      return (
          rpn_loss1_metric,
          rpn_loss2_metric,
          rcnn_loss1_metric,
          rcnn_loss2_metric,
          rpn_acc_metric,
          rpn_l1_loss_metric,
          rcnn_acc_metric,
          rcnn_l1_loss_metric,
      )
  
imports: import argparse
  import os
  import logging
  import time
  import gluoncv
  import mxnet
  import numpy
  from data import *
  from gluoncv import data, utils
  from gluoncv.data.batchify import Append, FasterRCNNTrainBatchify, Tuple
  from gluoncv.data.transforms.presets.rcnn import FasterRCNNDefaultTrainTransform, FasterRCNNDefaultValTransform
  from gluoncv.model_zoo import get_model
  from gluoncv.utils.metrics.coco_detection import COCODetectionMetric
  from gluoncv.utils.metrics.rcnn import RCNNAccMetric, RCNNL1LossMetric, RPNAccMetric, RPNL1LossMetric
  from gluoncv.utils.metrics.voc_detection import VOC07MApMetric
  from gluoncv.utils.parallel import Parallel, Parallelizable
  from model import faster_rcnn_resnet101_v1d_custom, faster_rcnn_resnet50_v1b_custom
  from mxnet import autograd, gluon
  from mxnet.contrib import amp
label_desc: Use image node_id 2 for calling the ForwardBackwardTask obj's underlying member method code with example usage: obj.forward_backward(x) and returns: rpn_loss1_metric,  rpn_loss2_metric,  rcnn_loss1_metric,  rcnn_loss2_metric,  rpn_acc_metric,  rpn_l1_loss_metric,  rcnn_acc_metric,  rcnn_l1_loss_metric