code: def assign_anchor_fpn(
      self, gt_label, anchors, landmark=False, prefix="face"
  ):
      IOU = config.TRAIN.CASCADE_OVERLAP
  
      gt_boxes = gt_label["gt_boxes"]
      # _label = gt_label['gt_label']
      # clean up boxes
      # nonneg = np.where(_label[:] != -1)[0]
      # gt_boxes = gt_boxes[nonneg]
      if landmark:
          gt_landmarks = gt_label["gt_landmarks"]
          # gt_landmarks = gt_landmarks[nonneg]
          assert gt_boxes.shape[0] == gt_landmarks.shape[0]
      # scales = np.array(scales, dtype=np.float32)
      feat_strides = config.RPN_FEAT_STRIDE
      bbox_pred_len = 4
      landmark_pred_len = 10
      num_anchors = anchors.shape[0]
      A = self.A
      total_anchors = num_anchors
      feat_height, feat_width = (
          config.SCALES[0][0] // self.stride,
          config.SCALES[0][0] // self.stride,
      )
  
      # print('total_anchors', anchors.shape[0], len(inds_inside), file=sys.stderr)
  
      # label: 1 is positive, 0 is negative, -1 is dont care
      labels = np.empty((num_anchors,), dtype=np.float32)
      labels.fill(-1)
      # print('BB', anchors.shape, len(inds_inside))
      # print('gt_boxes', gt_boxes.shape, file=sys.stderr)
      # tb = datetime.datetime.now()
      # self._times[0] += (tb-ta).total_seconds()
      # ta = datetime.datetime.now()
  
      if gt_boxes.size > 0:
          # overlap between the anchors and the gt boxes
          # overlaps (ex, gt)
          overlaps = bbox_overlaps(
              anchors.astype(np.float), gt_boxes.astype(np.float)
          )
          argmax_overlaps = overlaps.argmax(axis=1)
          # print('AAA', argmax_overlaps.shape)
          max_overlaps = overlaps[
              np.arange(num_anchors), argmax_overlaps
          ]
          gt_argmax_overlaps = overlaps.argmax(axis=0)
          gt_max_overlaps = overlaps[
              gt_argmax_overlaps, np.arange(overlaps.shape[1])
          ]
          gt_argmax_overlaps = np.where(overlaps == gt_max_overlaps)[0]
  
          if not config.TRAIN.RPN_CLOBBER_POSITIVES:
              # assign bg labels first so that positive labels can clobber them
              labels[max_overlaps < IOU[0]] = 0
  
          # fg label: for each gt, anchor with highest overlap
          if config.TRAIN.RPN_FORCE_POSITIVE:
              labels[gt_argmax_overlaps] = 1
  
          # fg label: above threshold IoU
          labels[max_overlaps >= IOU[1]] = 1
  
          if config.TRAIN.RPN_CLOBBER_POSITIVES:
              # assign bg labels last so that negative labels can clobber positives
              labels[max_overlaps < IOU[0]] = 0
      else:
          labels[:] = 0
      fg_inds = np.where(labels == 1)[0]
      # print('fg count', len(fg_inds))
  
      # subsample positive labels if we have too many
      if config.TRAIN.RPN_ENABLE_OHEM == 0:
          fg_inds = np.where(labels == 1)[0]
          num_fg = int(
              config.TRAIN.RPN_FG_FRACTION * config.TRAIN.RPN_BATCH_SIZE
          )
          if len(fg_inds) > num_fg:
              disable_inds = npr.choice(
                  fg_inds, size=(len(fg_inds) - num_fg), replace=False
              )
              if DEBUG:
                  disable_inds = fg_inds[: (len(fg_inds) - num_fg)]
              labels[disable_inds] = -1
  
          # subsample negative labels if we have too many
          num_bg = config.TRAIN.RPN_BATCH_SIZE - np.sum(labels == 1)
          bg_inds = np.where(labels == 0)[0]
          if len(bg_inds) > num_bg:
              disable_inds = npr.choice(
                  bg_inds, size=(len(bg_inds) - num_bg), replace=False
              )
              if DEBUG:
                  disable_inds = bg_inds[: (len(bg_inds) - num_bg)]
              labels[disable_inds] = -1
  
          # fg_inds = np.where(labels == 1)[0]
          # num_fg = len(fg_inds)
          # num_bg = num_fg*int(1.0/config.TRAIN.RPN_FG_FRACTION-1)
  
          # bg_inds = np.where(labels == 0)[0]
          # if len(bg_inds) > num_bg:
          #    disable_inds = npr.choice(bg_inds, size=(len(bg_inds) - num_bg), replace=False)
          #    if DEBUG:
          #        disable_inds = bg_inds[:(len(bg_inds) - num_bg)]
          #    labels[disable_inds] = -1
      else:
          fg_inds = np.where(labels == 1)[0]
          num_fg = len(fg_inds)
          bg_inds = np.where(labels == 0)[0]
          num_bg = len(bg_inds)
  
      # print('anchor stat', num_fg, num_bg)
  
      bbox_targets = np.zeros(
          (num_anchors, bbox_pred_len), dtype=np.float32
      )
      if gt_boxes.size > 0:
          # print('GT', gt_boxes.shape, gt_boxes[argmax_overlaps, :4].shape)
          bbox_targets[:, :] = bbox_transform(
              anchors, gt_boxes[argmax_overlaps, :]
          )
          # bbox_targets[:,4] = gt_blur
      # tb = datetime.datetime.now()
      # self._times[1] += (tb-ta).total_seconds()
      # ta = datetime.datetime.now()
  
      bbox_weights = np.zeros(
          (num_anchors, bbox_pred_len), dtype=np.float32
      )
      # bbox_weights[labels == 1, :] = np.array(config.TRAIN.RPN_BBOX_WEIGHTS)
      bbox_weights[labels == 1, 0:4] = 1.0
      if bbox_pred_len > 4:
          bbox_weights[labels == 1, 4:bbox_pred_len] = 0.1
  
      if landmark:
          landmark_targets = np.zeros(
              (num_anchors, landmark_pred_len), dtype=np.float32
          )
          landmark_weights = np.zeros(
              (num_anchors, landmark_pred_len), dtype=np.float32
          )
          # landmark_weights[labels == 1, :] = np.array(config.TRAIN.RPN_LANDMARK_WEIGHTS)
          if landmark_pred_len == 10:
              landmark_weights[labels == 1, :] = 1.0
          elif landmark_pred_len == 15:
              v = [1.0, 1.0, 0.1] * 5
              assert len(v) == 15
              landmark_weights[labels == 1, :] = np.array(v)
          else:
              assert False
          # TODO here
          if gt_landmarks.size > 0:
              # print('AAA',argmax_overlaps)
              a_landmarks = gt_landmarks[argmax_overlaps, :, :]
              landmark_targets[:] = landmark_transform(
                  anchors, a_landmarks
              )
              invalid = np.where(a_landmarks[:, 0, 2] < 0.0)[0]
              # assert len(invalid)==0
              # landmark_weights[invalid, :] = np.array(config.TRAIN.RPN_INVALID_LANDMARK_WEIGHTS)
              landmark_weights[invalid, :] = 0.0
      # tb = datetime.datetime.now()
      # self._times[2] += (tb-ta).total_seconds()
      # ta = datetime.datetime.now()
      bbox_targets[:, 0::4] = (
          bbox_targets[:, 0::4] / config.TRAIN.BBOX_STDS[0]
      )
      bbox_targets[:, 1::4] = (
          bbox_targets[:, 1::4] / config.TRAIN.BBOX_STDS[1]
      )
      bbox_targets[:, 2::4] = (
          bbox_targets[:, 2::4] / config.TRAIN.BBOX_STDS[2]
      )
      bbox_targets[:, 3::4] = (
          bbox_targets[:, 3::4] / config.TRAIN.BBOX_STDS[3]
      )
  
      # print('CC', anchors.shape, len(inds_inside))
      label = {}
      _label = labels.reshape(
          (1, feat_height, feat_width, A)
      ).transpose(0, 3, 1, 2)
      _label = _label.reshape((1, A * feat_height * feat_width))
      bbox_target = bbox_targets.reshape(
          (1, feat_height * feat_width, A * bbox_pred_len)
      ).transpose(0, 2, 1)
      bbox_weight = bbox_weights.reshape(
          (1, feat_height * feat_width, A * bbox_pred_len)
      ).transpose((0, 2, 1))
      label["%s_label" % prefix] = _label[0]
      label["%s_bbox_target" % prefix] = bbox_target[0]
      label["%s_bbox_weight" % prefix] = bbox_weight[0]
      if landmark:
          landmark_target = landmark_target.reshape(
              (1, feat_height * feat_width, A * landmark_pred_len)
          ).transpose(0, 2, 1)
          landmark_target /= config.TRAIN.LANDMARK_STD
          landmark_weight = landmark_weight.reshape(
              (1, feat_height * feat_width, A * landmark_pred_len)
          ).transpose((0, 2, 1))
          label["%s_landmark_target" % prefix] = landmark_target[0]
          label["%s_landmark_weight" % prefix] = landmark_weight[0]
  
      return label
  
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 3 for calling the CascadeRefineOperator obj's underlying member method code with example usage: obj.assign_anchor_fpn(gt_label, anchors, landmark, prefix) and returns: label