code: def forward(self, is_train, req, in_data, out_data, aux):
      self.nbatch += 1
      ta = datetime.datetime.now()
      global STAT
      A = config.NUM_ANCHORS
  
      cls_label_t0 = in_data[0].asnumpy()  # BS, AHW
      cls_score_t0 = in_data[1].asnumpy()  # BS, C, AHW
      cls_score = in_data[2].asnumpy()  # BS, C, AHW
      # labels_raw = in_data[1].asnumpy() #BS, ANCHORS
      bbox_pred_t0 = in_data[3].asnumpy()  # BS, AC, HW
      bbox_target_t0 = in_data[4].asnumpy()  # BS, AC, HW
      cls_label_raw = in_data[5].asnumpy()  # BS, AHW
      gt_boxes = in_data[6].asnumpy()  # BS, N, C=4+1
      # imgs = in_data[7].asnumpy().astype(np.uint8)
  
      batch_size = cls_score.shape[0]
      num_anchors = cls_score.shape[2]
      # print('in cas', cls_score.shape, bbox_target.shape)
  
      labels_out = np.zeros(
          shape=(batch_size, num_anchors), dtype=np.float32
      )
      bbox_target_out = np.zeros(
          shape=bbox_target_t0.shape, dtype=np.float32
      )
      anchor_weight = np.zeros(
          (batch_size, num_anchors, 1), dtype=np.float32
      )
      valid_count = np.zeros((batch_size, 1), dtype=np.float32)
  
      bbox_pred_t0 = bbox_pred_t0.transpose((0, 2, 1))
      bbox_pred_t0 = bbox_pred_t0.reshape(
          (bbox_pred_t0.shape[0], -1, 4)
      )  # BS, H*W*A, C
      bbox_target_t0 = bbox_target_t0.transpose((0, 2, 1))
      bbox_target_t0 = bbox_target_t0.reshape(
          (bbox_target_t0.shape[0], -1, 4)
      )
  
      # print('anchor_weight', anchor_weight.shape)
  
      # assert labels.shape[0]==1
      # assert cls_score.shape[0]==1
      # assert bbox_weight.shape[0]==1
      # print('shape', cls_score.shape, labels.shape, file=sys.stderr)
      # print('bbox_weight 0', bbox_weight.shape, file=sys.stderr)
      # bbox_weight = np.zeros( (labels_raw.shape[0], labels_raw.shape[1], 4), dtype=np.float32)
      _stat = [0, 0, 0]
      SEL_TOPK = config.TRAIN.RPN_BATCH_SIZE
      FAST = False
      for ibatch in range(batch_size):
          # bgr = imgs[ibatch].transpose( (1,2,0) )[:,:,::-1]
  
          if not FAST:
              _gt_boxes = gt_boxes[ibatch]  # N, 4+1
              _gtind = len(np.where(_gt_boxes[:, 4] >= 0)[0])
              # print('gt num', _gtind)
              _gt_boxes = _gt_boxes[0:_gtind, :]
  
              # anchors_t1 = self.ori_anchors.copy()
              # _cls_label_raw = cls_label_raw[ibatch] #AHW
              # _cls_label_raw = _cls_label_raw.reshape( (A, -1) ).transpose( (1,0) ).reshape( (-1,) ) #HWA
              # fg_ind_raw = np.where(_cls_label_raw>0)[0]
              # _bbox_target_t0 = bbox_target_t0[ibatch][fg_ind_raw]
              # _bbox_pred_t0 = bbox_pred_t0[ibatch][fg_ind_raw]
              # anchors_t1_pos = self.apply_bbox_pred(_bbox_pred_t0, ind=fg_ind_raw)
              # anchors_t1[fg_ind_raw,:] = anchors_t1_pos
  
              anchors_t1 = self.apply_bbox_pred(bbox_pred_t0[ibatch])
              assert anchors_t1.shape[0] == self.ori_anchors.shape[0]
  
              # for i in range(_gt_boxes.shape[0]):
              #  box = _gt_boxes[i].astype(np.int)
              #  print('%d: gt%d'%(self.nbatch, i), box)
              #  #color = (0,0,255)
              #  #cv2.rectangle(img, (box[0], box[1]), (box[2], box[3]), color, 2)
              # for i in range(anchors_t1.shape[0]):
              #  box1 = self.ori_anchors[i].astype(np.int)
              #  box2 = anchors_t1[i].astype(np.int)
              #  print('%d %d: anchorscompare %d'%(self.nbatch, self.stride, i), box1, box2)
              # color = (255,255,0)
              # cv2.rectangle(img, (box[0], box[1]), (box[2], box[3]), color, 2)
              # filename = "./debug/%d_%d_%d.jpg"%(self.nbatch, ibatch, stride)
              # cv2.imwrite(filename, img)
              # print(filename)
              # gt_label = {'gt_boxes': gt_anchors, 'gt_label' : labels_raw[ibatch]}
              gt_label = {"gt_boxes": _gt_boxes}
              new_label_dict = self.assign_anchor_fpn(
                  gt_label, anchors_t1, False, prefix=self.prefix
              )
              labels = new_label_dict["%s_label" % self.prefix]  # AHW
              new_bbox_target = new_label_dict[
                  "%s_bbox_target" % self.prefix
              ]  # AC,HW
              # print('assign ret', labels.shape, new_bbox_target.shape)
              _anchor_weight = np.zeros(
                  (num_anchors, 1), dtype=np.float32
              )
              fg_score = (
                  cls_score[ibatch, 1, :] - cls_score[ibatch, 0, :]
              )
              fg_inds = np.where(labels > 0)[0]
              num_fg = int(
                  config.TRAIN.RPN_FG_FRACTION
                  * config.TRAIN.RPN_BATCH_SIZE
              )
              origin_num_fg = len(fg_inds)
              # continue
              # print('cas fg', len(fg_inds), num_fg, file=sys.stderr)
              if len(fg_inds) > num_fg:
                  if self.mode == 0:
                      disable_inds = np.random.choice(
                          fg_inds,
                          size=(len(fg_inds) - num_fg),
                          replace=False,
                      )
                      labels[disable_inds] = -1
                  else:
                      pos_ohem_scores = fg_score[fg_inds]
                      order_pos_ohem_scores = (
                          pos_ohem_scores.ravel().argsort()
                      )
                      sampled_inds = fg_inds[
                          order_pos_ohem_scores[:num_fg]
                      ]
                      labels[fg_inds] = -1
                      labels[sampled_inds] = 1
  
              n_fg = np.sum(labels > 0)
              fg_inds = np.where(labels > 0)[0]
              num_bg = config.TRAIN.RPN_BATCH_SIZE - n_fg
              if self.mode == 2:
                  num_bg = max(
                      48,
                      n_fg
                      * int(1.0 / config.TRAIN.RPN_FG_FRACTION - 1),
                  )
  
              bg_inds = np.where(labels == 0)[0]
              origin_num_bg = len(bg_inds)
              if num_bg == 0:
                  labels[bg_inds] = -1
              elif len(bg_inds) > num_bg:
                  # sort ohem scores
  
                  if self.mode == 0:
                      disable_inds = np.random.choice(
                          bg_inds,
                          size=(len(bg_inds) - num_bg),
                          replace=False,
                      )
                      labels[disable_inds] = -1
                  else:
                      neg_ohem_scores = fg_score[bg_inds]
                      order_neg_ohem_scores = (
                          neg_ohem_scores.ravel().argsort()[::-1]
                      )
                      sampled_inds = bg_inds[
                          order_neg_ohem_scores[:num_bg]
                      ]
                      # print('sampled_inds_bg', sampled_inds, file=sys.stderr)
                      labels[bg_inds] = -1
                      labels[sampled_inds] = 0
  
              if n_fg > 0:
                  order0_labels = (
                      labels.reshape((1, A, -1))
                      .transpose((0, 2, 1))
                      .reshape((-1,))
                  )
                  bbox_fg_inds = np.where(order0_labels > 0)[0]
                  # print('bbox_fg_inds, order0 ', bbox_fg_inds, file=sys.stderr)
                  _anchor_weight[bbox_fg_inds, :] = 1.0
              anchor_weight[ibatch] = _anchor_weight
              valid_count[ibatch][0] = n_fg
              labels_out[ibatch] = labels
              # print('labels_out', self.stride, ibatch, labels)
              bbox_target_out[ibatch] = new_bbox_target
              # print('cascade stat', self.stride, ibatch, len(labels), len(np.where(labels==1)[0]), len(np.where(labels==0)[0]))
          else:  # FAST MODE
              fg_score_t0 = (
                  cls_score_t0[ibatch, 1, :]
                  - cls_score_t0[ibatch, 0, :]
              )
              sort_idx_t0 = np.argsort(fg_score_t0.flatten())[::-1][
                  0:SEL_TOPK
              ]
              _bbox_pred_t0 = bbox_pred_t0[ibatch][sort_idx_t0]
              _bbox_target_t0 = bbox_target_t0[ibatch][sort_idx_t0]
              # print('SEL fg score:', fg_score_t0[sort_idx[-1]], fg_score_t0[sort_idx[0]])
              anchors_t0 = self.apply_bbox_pred(_bbox_pred_t0)
              gt_anchors = self.apply_bbox_pred(_bbox_target_t0)
              # gt_label = {'gt_boxes': gt_anchors, 'gt_label' : labels_raw[ibatch]}
              gt_label = {"gt_boxes": gt_anchors}
              new_label_dict = self.assign_anchor_fpn(
                  gt_label, anchors_t0, False, prefix=self.prefix
              )
              labels = new_label_dict["%s_label" % self.prefix]
              new_bbox_target = new_label_dict[
                  "%s_bbox_target" % self.prefix
              ]
              # print('assign ret', labels.shape, new_bbox_target.shape)
              _anchor_weight = np.zeros(
                  (num_anchors, 1), dtype=np.float32
              )
              fg_score = (
                  cls_score[ibatch, 1, :] - cls_score[ibatch, 0, :]
              )
              fg_inds = np.where(labels > 0)[0]
              _labels = np.empty(shape=labels.shape, dtype=np.float32)
              _labels.fill(-1)
              _labels[sort_idx_idx] = labels
  
              anchor_weight[ibatch] = _anchor_weight
              valid_count[ibatch][0] = len(fg_inds)
              labels_out[ibatch] = _labels
              # print('labels_out', self.stride, ibatch, labels)
              bbox_target_out[ibatch] = new_bbox_target
  
      # print('cascade pos stat', self.stride, batch_size, np.sum(valid_count))
      for ind, val in enumerate(
          [labels_out, bbox_target_out, anchor_weight, valid_count]
      ):
          val = mx.nd.array(val)
          self.assign(out_data[ind], req[ind], val)
      tb = datetime.datetime.now()
  
imports: from __future__ import print_function
  import sys
  import mxnet
  import numpy
  import datetime
  from distutils.util import strtobool
  from ..config import config, generate_config
  from ..processing.generate_anchor import generate_anchors, anchors_plane
  from ..processing.bbox_transform import bbox_overlaps, bbox_transform, landmark_transform
label_desc: Use image node_id 4 for calling the CascadeRefineOperator obj's underlying member method code with example usage: obj.forward(is_train, req, in_data, out_data, aux) without return types