code: def get_out(
      conv_fpn_feat,
      prefix,
      stride,
      landmark=False,
      lr_mult=1.0,
      gt_boxes=None,
  ):
      A = config.NUM_ANCHORS
      bbox_pred_len = 4
      landmark_pred_len = 10
      if config.USE_BLUR:
          bbox_pred_len = 5
      if config.USE_OCCLUSION:
          landmark_pred_len = 15
      ret_group = []
      num_anchors = config.RPN_ANCHOR_CFG[str(stride)]["NUM_ANCHORS"]
      cls_label = mx.symbol.Variable(
          name="%s_label_stride%d" % (prefix, stride)
      )
      bbox_target = mx.symbol.Variable(
          name="%s_bbox_target_stride%d" % (prefix, stride)
      )
      bbox_weight = mx.symbol.Variable(
          name="%s_bbox_weight_stride%d" % (prefix, stride)
      )
      if landmark:
          landmark_target = mx.symbol.Variable(
              name="%s_landmark_target_stride%d" % (prefix, stride)
          )
          landmark_weight = mx.symbol.Variable(
              name="%s_landmark_weight_stride%d" % (prefix, stride)
          )
      conv_feat = conv_fpn_feat[stride]
      rpn_relu = head_module(
          conv_feat,
          F2 * config.CONTEXT_FILTER_RATIO,
          F1,
          "rf_head_stride%d" % stride,
      )
  
      rpn_cls_score = conv_only(
          rpn_relu,
          "%s_rpn_cls_score_stride%d" % (prefix, stride),
          2 * num_anchors,
          kernel=(1, 1),
          pad=(0, 0),
          stride=(1, 1),
      )
  
      rpn_bbox_pred = conv_only(
          rpn_relu,
          "%s_rpn_bbox_pred_stride%d" % (prefix, stride),
          bbox_pred_len * num_anchors,
          kernel=(1, 1),
          pad=(0, 0),
          stride=(1, 1),
      )
  
      # prepare rpn data
      rpn_cls_score_reshape = mx.symbol.Reshape(
          data=rpn_cls_score,
          shape=(0, 2, -1),
          name="%s_rpn_cls_score_reshape_stride%s" % (prefix, stride),
      )
  
      rpn_bbox_pred_reshape = mx.symbol.Reshape(
          data=rpn_bbox_pred,
          shape=(0, 0, -1),
          name="%s_rpn_bbox_pred_reshape_stride%s" % (prefix, stride),
      )
      if landmark:
          rpn_landmark_pred = conv_only(
              rpn_relu,
              "%s_rpn_landmark_pred_stride%d" % (prefix, stride),
              landmark_pred_len * num_anchors,
              kernel=(1, 1),
              pad=(0, 0),
              stride=(1, 1),
          )
          rpn_landmark_pred_reshape = mx.symbol.Reshape(
              data=rpn_landmark_pred,
              shape=(0, 0, -1),
              name="%s_rpn_landmark_pred_reshape_stride%s"
              % (prefix, stride),
          )
  
      if config.TRAIN.RPN_ENABLE_OHEM >= 2:
          label, anchor_weight, pos_count = mx.sym.Custom(
              op_type="rpn_fpn_ohem3",
              stride=int(stride),
              network=config.network,
              dataset=config.dataset,
              prefix=prefix,
              cls_score=rpn_cls_score_reshape,
              labels=cls_label,
          )
  
          _bbox_weight = mx.sym.tile(
              anchor_weight, (1, 1, bbox_pred_len)
          )
          _bbox_weight = _bbox_weight.reshape(
              (0, -1, A * bbox_pred_len)
          ).transpose((0, 2, 1))
          bbox_weight = mx.sym.elemwise_mul(
              bbox_weight,
              _bbox_weight,
              name="%s_bbox_weight_mul_stride%s" % (prefix, stride),
          )
  
          if landmark:
              _landmark_weight = mx.sym.tile(
                  anchor_weight, (1, 1, landmark_pred_len)
              )
              _landmark_weight = _landmark_weight.reshape(
                  (0, -1, A * landmark_pred_len)
              ).transpose((0, 2, 1))
              landmark_weight = mx.sym.elemwise_mul(
                  landmark_weight,
                  _landmark_weight,
                  name="%s_landmark_weight_mul_stride%s"
                  % (prefix, stride),
              )
      else:
          label = cls_label
          # if not config.FACE_LANDMARK:
          #  label, bbox_weight = mx.sym.Custom(op_type='rpn_fpn_ohem', stride=int(stride), cls_score=rpn_cls_score_reshape, bbox_weight = bbox_weight , labels = label)
          # else:
          #  label, bbox_weight, landmark_weight = mx.sym.Custom(op_type='rpn_fpn_ohem2', stride=int(stride), cls_score=rpn_cls_score_reshape, bbox_weight = bbox_weight, landmark_weight=landmark_weight, labels = label)
      # cls loss
      rpn_cls_prob = mx.symbol.SoftmaxOutput(
          data=rpn_cls_score_reshape,
          label=label,
          multi_output=True,
          normalization="valid",
          use_ignore=True,
          ignore_label=-1,
          grad_scale=lr_mult,
          name="%s_rpn_cls_prob_stride%d" % (prefix, stride),
      )
      ret_group.append(rpn_cls_prob)
      ret_group.append(mx.sym.BlockGrad(label))
  
      pos_count = mx.symbol.sum(pos_count)
      pos_count = pos_count + 0.001  # avoid zero
  
      # bbox loss
      bbox_diff = rpn_bbox_pred_reshape - bbox_target
      bbox_diff = bbox_diff * bbox_weight
      rpn_bbox_loss_ = mx.symbol.smooth_l1(
          name="%s_rpn_bbox_loss_stride%d_" % (prefix, stride),
          scalar=3.0,
          data=bbox_diff,
      )
      bbox_lr_mode0 = (
          0.25
          * lr_mult
          * config.TRAIN.BATCH_IMAGES
          / config.TRAIN.RPN_BATCH_SIZE
      )
      landmark_lr_mode0 = 0.4 * config.LANDMARK_LR_MULT * bbox_lr_mode0
      if config.LR_MODE == 0:
          rpn_bbox_loss = mx.sym.MakeLoss(
              name="%s_rpn_bbox_loss_stride%d" % (prefix, stride),
              data=rpn_bbox_loss_,
              grad_scale=bbox_lr_mode0,
          )
      else:
          rpn_bbox_loss_ = mx.symbol.broadcast_div(
              rpn_bbox_loss_, pos_count
          )
          rpn_bbox_loss = mx.sym.MakeLoss(
              name="%s_rpn_bbox_loss_stride%d" % (prefix, stride),
              data=rpn_bbox_loss_,
              grad_scale=0.5 * lr_mult,
          )
      ret_group.append(rpn_bbox_loss)
      ret_group.append(mx.sym.BlockGrad(bbox_weight))
  
      # landmark loss
      if landmark:
          landmark_diff = rpn_landmark_pred_reshape - landmark_target
          landmark_diff = landmark_diff * landmark_weight
          rpn_landmark_loss_ = mx.symbol.smooth_l1(
              name="%s_rpn_landmark_loss_stride%d_" % (prefix, stride),
              scalar=3.0,
              data=landmark_diff,
          )
          if config.LR_MODE == 0:
              rpn_landmark_loss = mx.sym.MakeLoss(
                  name="%s_rpn_landmark_loss_stride%d"
                  % (prefix, stride),
                  data=rpn_landmark_loss_,
                  grad_scale=landmark_lr_mode0,
              )
          else:
              rpn_landmark_loss_ = mx.symbol.broadcast_div(
                  rpn_landmark_loss_, pos_count
              )
              rpn_landmark_loss = mx.sym.MakeLoss(
                  name="%s_rpn_landmark_loss_stride%d"
                  % (prefix, stride),
                  data=rpn_landmark_loss_,
                  grad_scale=0.2 * config.LANDMARK_LR_MULT * lr_mult,
              )
          ret_group.append(rpn_landmark_loss)
          ret_group.append(mx.sym.BlockGrad(landmark_weight))
      if config.USE_3D:
          from rcnn.PY_OP import rpn_3d_mesh
  
          pass
      if config.CASCADE > 0:
          if config.CASCADE_MODE == 0:
              body = rpn_relu
          elif config.CASCADE_MODE == 1:
              body = head_module(
                  conv_feat,
                  F2 * config.CONTEXT_FILTER_RATIO,
                  F1,
                  "%s_head_stride%d_cas" % (PREFIX, stride),
              )
          elif config.CASCADE_MODE == 2:
              body = conv_feat + rpn_relu
              body = head_module(
                  body,
                  F2 * config.CONTEXT_FILTER_RATIO,
                  F1,
                  "%s_head_stride%d_cas" % (PREFIX, stride),
              )
          else:
              body = head_module(
                  conv_feat,
                  F2 * config.CONTEXT_FILTER_RATIO,
                  F1,
                  "%s_head_stride%d_cas" % (PREFIX, stride),
              )
              body = mx.sym.concat(
                  body,
                  rpn_cls_score,
                  rpn_bbox_pred,
                  rpn_landmark_pred,
                  dim=1,
              )
  
          # cls_pred = rpn_cls_prob
          cls_pred_t0 = rpn_cls_score_reshape
          cls_label_raw = cls_label
          cls_label_t0 = label
          bbox_pred_t0 = rpn_bbox_pred_reshape
          # bbox_pred = rpn_bbox_pred
          # bbox_pred = mx.sym.transpose(bbox_pred, (0, 2, 3, 1))
          # bbox_pred_len = 4
          # bbox_pred = mx.sym.reshape(bbox_pred, (0, -1, bbox_pred_len))
          bbox_label_t0 = bbox_target
          # prefix = prefix+'2'
          for casid in range(config.CASCADE):
              # pseudo-code
              # anchor_label = GENANCHOR(bbox_label, bbox_pred, stride)
              # bbox_label = F(anchor_label, bbox_pred)
              # bbox_label = bbox_label - bbox_pred
              cls_pred = conv_only(
                  body,
                  "%s_rpn_cls_score_stride%d_cas%d"
                  % (prefix, stride, casid),
                  2 * num_anchors,
                  kernel=(1, 1),
                  pad=(0, 0),
                  stride=(1, 1),
              )
              rpn_cls_score_reshape = mx.symbol.Reshape(
                  data=cls_pred,
                  shape=(0, 2, -1),
                  name="%s_rpn_cls_score_reshape_stride%s_cas%d"
                  % (prefix, stride, casid),
              )
  
              # bbox_label equals to bbox_target
              # cls_pred, cls_label, bbox_pred, bbox_label, bbox_weight, pos_count = mx.sym.Custom(op_type='cascade_refine', stride=int(stride), network=config.network, dataset=config.dataset, prefix=prefix, cls_pred=cls_pred, cls_label = cls_label, bbox_pred = bbox_pred, bbox_label = bbox_label)
              # cls_label, bbox_label, anchor_weight, pos_count = mx.sym.Custom(op_type='cascade_refine', stride=int(stride), network=config.network, dataset=config.dataset, prefix=prefix, cls_pred_t0=cls_pred_t0, cls_label_t0 = cls_label_t0, cls_pred = rpn_cls_score_reshape, bbox_pred_t0 = bbox_pred_t0, bbox_label_t0 = bbox_label_t0)
              (
                  cls_label,
                  bbox_label,
                  anchor_weight,
                  pos_count,
              ) = mx.sym.Custom(
                  op_type="cascade_refine",
                  stride=int(stride),
                  network=config.network,
                  dataset=config.dataset,
                  prefix=prefix,
                  cls_label_t0=cls_label_t0,
                  cls_pred_t0=cls_pred_t0,
                  cls_pred=rpn_cls_score_reshape,
                  bbox_pred_t0=bbox_pred_t0,
                  bbox_label_t0=bbox_label_t0,
                  cls_label_raw=cls_label_raw,
                  cas_gt_boxes=gt_boxes,
              )
              if stride in config.CASCADE_CLS_STRIDES:
                  rpn_cls_prob = mx.symbol.SoftmaxOutput(
                      data=rpn_cls_score_reshape,
                      label=cls_label,
                      multi_output=True,
                      normalization="valid",
                      use_ignore=True,
                      ignore_label=-1,
                      grad_scale=lr_mult,
                      name="%s_rpn_cls_prob_stride%d_cas%d"
                      % (prefix, stride, casid),
                  )
                  ret_group.append(rpn_cls_prob)
                  ret_group.append(mx.sym.BlockGrad(cls_label))
              if stride in config.CASCADE_BBOX_STRIDES:
                  bbox_pred = conv_only(
                      body,
                      "%s_rpn_bbox_pred_stride%d_cas%d"
                      % (prefix, stride, casid),
                      bbox_pred_len * num_anchors,
                      kernel=(1, 1),
                      pad=(0, 0),
                      stride=(1, 1),
                  )
  
                  rpn_bbox_pred_reshape = mx.symbol.Reshape(
                      data=bbox_pred,
                      shape=(0, 0, -1),
                      name="%s_rpn_bbox_pred_reshape_stride%s_cas%d"
                      % (prefix, stride, casid),
                  )
                  _bbox_weight = mx.sym.tile(
                      anchor_weight, (1, 1, bbox_pred_len)
                  )
                  _bbox_weight = _bbox_weight.reshape(
                      (0, -1, A * bbox_pred_len)
                  ).transpose((0, 2, 1))
                  bbox_weight = _bbox_weight
                  pos_count = mx.symbol.sum(pos_count)
                  pos_count = pos_count + 0.01  # avoid zero
                  # bbox_weight = mx.sym.elemwise_mul(bbox_weight, _bbox_weight, name='%s_bbox_weight_mul_stride%s'%(prefix,stride))
                  # bbox loss
                  bbox_diff = rpn_bbox_pred_reshape - bbox_label
                  bbox_diff = bbox_diff * bbox_weight
                  rpn_bbox_loss_ = mx.symbol.smooth_l1(
                      name="%s_rpn_bbox_loss_stride%d_cas%d"
                      % (prefix, stride, casid),
                      scalar=3.0,
                      data=bbox_diff,
                  )
                  if config.LR_MODE == 0:
                      rpn_bbox_loss = mx.sym.MakeLoss(
                          name="%s_rpn_bbox_loss_stride%d_cas%d"
                          % (prefix, stride, casid),
                          data=rpn_bbox_loss_,
                          grad_scale=bbox_lr_mode0,
                      )
                  else:
                      rpn_bbox_loss_ = mx.symbol.broadcast_div(
                          rpn_bbox_loss_, pos_count
                      )
                      rpn_bbox_loss = mx.sym.MakeLoss(
                          name="%s_rpn_bbox_loss_stride%d_cas%d"
                          % (prefix, stride, casid),
                          data=rpn_bbox_loss_,
                          grad_scale=0.5 * lr_mult,
                      )
                  ret_group.append(rpn_bbox_loss)
                  ret_group.append(mx.sym.BlockGrad(bbox_weight))
                  # bbox_pred = rpn_bbox_pred_reshape
  
      return ret_group
  
file_path: insightface/detection/retinaface/rcnn/symbol/symbol_common.py
imports: import mxnet
  import mxnet.ndarray
  import numpy
  from rcnn.config import config
  from rcnn.PY_OP import rpn_fpn_ohem3, cascade_refine
label_desc: Use image node_id 12 for calling a global function with example usage: get_out(conv_fpn_feat, prefix, stride, landmark, lr_mult, gt_boxes) and returns: ret_group