class_docstr: FCOSLoss of Consistency Regularization
code: def hard_neg_mining(
      self,
      cls_score,
      loc_ltrb,
      quality,
      pos_ind,
      hard_neg_ind,
      loc_mask,
      loc_targets,
      iou_thresh=0.6,
  ):
      # get points locations and strides
      points_list = []
      strides_list = []
      scale_list = []
      scale = [0, 1, 2, 3, 4]
      for fpn_scale, fpn_stride, HW in zip(
          scale, self.fpn_stride, self.lvl_hw
      ):
          h, w = HW
          lvl_points = self.compute_locations_by_level(fpn_stride, h, w)
          points_list.append(lvl_points)
          lvl_strides = paddle.full([h * w, 1], fpn_stride)
          strides_list.append(lvl_strides)
          lvl_scales = paddle.full([h * w, 1], fpn_scale)
          scale_list.append(lvl_scales)
      points = paddle.concat(points_list, axis=0)
      strides = paddle.concat(strides_list, axis=0)
      scales = paddle.concat(scale_list, axis=0)
  
      # cls scores
      cls_vals = F.sigmoid(cls_score) * F.sigmoid(quality)
      max_vals = paddle.max(cls_vals, axis=-1)
      class_ind = paddle.argmax(cls_vals, axis=-1)
  
      ### calculate iou between positive and hard negative
      # decode pos bbox
      pos_cls = max_vals[pos_ind]
      pos_loc = loc_ltrb[pos_ind].reshape([-1, 4])
      pos_strides = strides[pos_ind]
      pos_points = points[pos_ind].reshape([-1, 2])
      pos_loc = pos_loc * pos_strides
      pos_bbox = self.decode_bbox(pos_loc, pos_points)
      pos_scales = scales[pos_ind]
      # decode hard negative bbox
      hard_neg_loc = loc_ltrb[hard_neg_ind].reshape([-1, 4])
      hard_neg_strides = strides[hard_neg_ind]
      hard_neg_points = points[hard_neg_ind].reshape([-1, 2])
      hard_neg_loc = hard_neg_loc * hard_neg_strides
      hard_neg_bbox = self.decode_bbox(hard_neg_loc, hard_neg_points)
      hard_neg_scales = scales[hard_neg_ind]
      # iou between pos bbox and hard negative bbox
      hard_neg_pos_iou = self.calcualate_iou(hard_neg_bbox, pos_bbox)
  
      ### select potential positives from hard negatives
      # scale flag
      scale_temp = paddle.abs(
          pos_scales.reshape([-1])[None, :]
          - hard_neg_scales.reshape([-1])[:, None]
      )
      scale_flag = scale_temp <= 1.0
      # iou flag
      iou_flag = hard_neg_pos_iou >= iou_thresh
      # same class flag
      pos_class = class_ind[pos_ind]
      hard_neg_class = class_ind[hard_neg_ind]
      class_flag = pos_class[None, :] - hard_neg_class[:, None]
      class_flag = class_flag == 0
      # hard negative point inside positive bbox flag
      ltrb_temp = paddle.stack(
          [
              hard_neg_points[:, None, 0] - pos_bbox[None, :, 0],
              hard_neg_points[:, None, 1] - pos_bbox[None, :, 1],
              pos_bbox[None, :, 2] - hard_neg_points[:, None, 0],
              pos_bbox[None, :, 3] - hard_neg_points[:, None, 1],
          ],
          axis=-1,
      )
      inside_flag = ltrb_temp.min(axis=-1) > 0
      # reset iou
      valid_flag = iou_flag & class_flag & inside_flag & scale_flag
      invalid_iou = paddle.zeros_like(hard_neg_pos_iou)
      hard_neg_pos_iou = paddle.where(
          valid_flag, hard_neg_pos_iou, invalid_iou
      )
      pos_hard_neg_max_iou = hard_neg_pos_iou.max(axis=-1)
      # selece potential pos
      potential_pos_ind = pos_hard_neg_max_iou > 0.0
      num_potential_pos = paddle.nonzero(potential_pos_ind).shape[0]
      if num_potential_pos == 0:
          return None
  
      ### calculate loc target：aggregate all matching bboxes as the bbox targets of potential pos
      # prepare data
      potential_points = hard_neg_points[potential_pos_ind].reshape(
          [-1, 2]
      )
      potential_strides = hard_neg_strides[potential_pos_ind]
      potential_valid_flag = valid_flag[potential_pos_ind]
      potential_pos_ind = hard_neg_ind[potential_pos_ind]
  
      # get cls and box of matching positives
      pos_cls = max_vals[pos_ind]
      expand_pos_bbox = paddle.expand(
          pos_bbox,
          shape=[
              num_potential_pos,
              pos_bbox.shape[0],
              pos_bbox.shape[1],
          ],
      )
      expand_pos_cls = paddle.expand(
          pos_cls, shape=[num_potential_pos, pos_cls.shape[0]]
      )
      invalid_cls = paddle.zeros_like(expand_pos_cls)
      expand_pos_cls = paddle.where(
          potential_valid_flag, expand_pos_cls, invalid_cls
      )
      expand_pos_cls = paddle.unsqueeze(expand_pos_cls, axis=-1)
      # aggregate box based on cls_score
      agg_bbox = (expand_pos_bbox * expand_pos_cls).sum(
          axis=1
      ) / expand_pos_cls.sum(axis=1)
      agg_ltrb = self.encode_bbox(agg_bbox, potential_points)
      agg_ltrb = agg_ltrb / potential_strides
  
      # loc target for all pos
      loc_targets[potential_pos_ind] = agg_ltrb
      loc_mask[potential_pos_ind] = 1.0
  
      return loc_mask, loc_targets
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import paddle
  import paddle.nn
  import paddle.nn.functional
  from ppdet.core.workspace import register
  from ppdet.modeling import ops
  from functools import partial
label_desc: Use image node_id 9 for calling the FCOSLossCR obj's underlying member method code with example usage: obj.hard_neg_mining(cls_score, loc_ltrb, quality, pos_ind, hard_neg_ind, loc_mask, loc_targets, iou_thresh) and returns: loc_mask,  loc_targets, None