class_docstr: Assign a corresponding gt bbox or background to each bbox.
  
  Each proposals will be assigned with `0` or a positive integer
  indicating the ground truth index.
  
  - 0: negative sample, no assigned gt
  - positive integer: positive sample, index (1-based) of assigned gt
  
  Args:
      topk (float): number of bbox selected in each level
docstr: Assign gt to bboxes.
  The assignment is done in following steps
  1. compute iou between all bbox (bbox of all pyramid levels) and gt
  2. compute center distance between all bbox and gt
  3. on each pyramid level, for each gt, select k bbox whose center
     are closest to the gt center, so we total select k*l bbox as
     candidates for each gt
  4. get corresponding iou for the these candidates, and compute the
     mean and std, set mean + std as the iou threshold
  5. select these candidates whose iou are greater than or equal to
     the threshold as postive
  6. limit the positive sample's center in gt
  Args:
      bboxes (np.array): Bounding boxes to be assigned, shape(n, 4).
      num_level_bboxes (List): num of bboxes in each level
      gt_bboxes (np.array): Groundtruth boxes, shape (k, 4).
      gt_bboxes_ignore (np.array, optional): Ground truth bboxes that are
          labelled as `ignored`, e.g., crowd boxes in COCO.
      gt_labels (np.array, optional): Label of gt_bboxes, shape (k, ).
code: def __call__(
      self,
      bboxes,
      num_level_bboxes,
      gt_bboxes,
      gt_bboxes_ignore=None,
      gt_labels=None,
  ):
      """Assign gt to bboxes.
      The assignment is done in following steps
      1. compute iou between all bbox (bbox of all pyramid levels) and gt
      2. compute center distance between all bbox and gt
      3. on each pyramid level, for each gt, select k bbox whose center
         are closest to the gt center, so we total select k*l bbox as
         candidates for each gt
      4. get corresponding iou for the these candidates, and compute the
         mean and std, set mean + std as the iou threshold
      5. select these candidates whose iou are greater than or equal to
         the threshold as postive
      6. limit the positive sample's center in gt
      Args:
          bboxes (np.array): Bounding boxes to be assigned, shape(n, 4).
          num_level_bboxes (List): num of bboxes in each level
          gt_bboxes (np.array): Groundtruth boxes, shape (k, 4).
          gt_bboxes_ignore (np.array, optional): Ground truth bboxes that are
              labelled as `ignored`, e.g., crowd boxes in COCO.
          gt_labels (np.array, optional): Label of gt_bboxes, shape (k, ).
      """
      bboxes = bboxes[:, :4]
      num_gt, num_bboxes = gt_bboxes.shape[0], bboxes.shape[0]
  
      # assign 0 by default
      assigned_gt_inds = np.zeros((num_bboxes,), dtype=np.int64)
  
      if num_gt == 0 or num_bboxes == 0:
          # No ground truth or boxes, return empty assignment
          max_overlaps = np.zeros((num_bboxes,))
          if num_gt == 0:
              # No truth, assign everything to background
              assigned_gt_inds[:] = 0
          if not np.any(gt_labels):
              assigned_labels = None
          else:
              assigned_labels = -np.ones((num_bboxes,), dtype=np.int64)
          return assigned_gt_inds, max_overlaps
  
      # compute iou between all bbox and gt
      overlaps = bbox_overlaps(bboxes, gt_bboxes)
      # compute center distance between all bbox and gt
      gt_cx = (gt_bboxes[:, 0] + gt_bboxes[:, 2]) / 2.0
      gt_cy = (gt_bboxes[:, 1] + gt_bboxes[:, 3]) / 2.0
      gt_points = np.stack((gt_cx, gt_cy), axis=1)
  
      bboxes_cx = (bboxes[:, 0] + bboxes[:, 2]) / 2.0
      bboxes_cy = (bboxes[:, 1] + bboxes[:, 3]) / 2.0
      bboxes_points = np.stack((bboxes_cx, bboxes_cy), axis=1)
  
      distances = np.sqrt(
          np.power(
              (bboxes_points[:, None, :] - gt_points[None, :, :]), 2
          ).sum(-1)
      )
  
      # Selecting candidates based on the center distance
      candidate_idxs = []
      start_idx = 0
      for bboxes_per_level in num_level_bboxes:
          # on each pyramid level, for each gt,
          # select k bbox whose center are closest to the gt center
          end_idx = start_idx + bboxes_per_level
          distances_per_level = distances[start_idx:end_idx, :]
          selectable_k = min(self.topk, bboxes_per_level)
          _, topk_idxs_per_level = topk_(
              distances_per_level, selectable_k, axis=0, largest=False
          )
          candidate_idxs.append(topk_idxs_per_level + start_idx)
          start_idx = end_idx
      candidate_idxs = np.concatenate(candidate_idxs, axis=0)
  
      # get corresponding iou for the these candidates, and compute the
      # mean and std, set mean + std as the iou threshold
      candidate_overlaps = overlaps[candidate_idxs, np.arange(num_gt)]
      overlaps_mean_per_gt = candidate_overlaps.mean(0)
      overlaps_std_per_gt = candidate_overlaps.std(0)
      overlaps_thr_per_gt = overlaps_mean_per_gt + overlaps_std_per_gt
  
      is_pos = candidate_overlaps >= overlaps_thr_per_gt[None, :]
  
      # limit the positive sample's center in gt
      for gt_idx in range(num_gt):
          candidate_idxs[:, gt_idx] += gt_idx * num_bboxes
      ep_bboxes_cx = np.broadcast_to(
          bboxes_cx.reshape(1, -1), [num_gt, num_bboxes]
      ).reshape(-1)
      ep_bboxes_cy = np.broadcast_to(
          bboxes_cy.reshape(1, -1), [num_gt, num_bboxes]
      ).reshape(-1)
      candidate_idxs = candidate_idxs.reshape(-1)
  
      # calculate the left, top, right, bottom distance between positive
      # bbox center and gt side
      l_ = (
          ep_bboxes_cx[candidate_idxs].reshape(-1, num_gt)
          - gt_bboxes[:, 0]
      )
      t_ = (
          ep_bboxes_cy[candidate_idxs].reshape(-1, num_gt)
          - gt_bboxes[:, 1]
      )
      r_ = gt_bboxes[:, 2] - ep_bboxes_cx[candidate_idxs].reshape(
          -1, num_gt
      )
      b_ = gt_bboxes[:, 3] - ep_bboxes_cy[candidate_idxs].reshape(
          -1, num_gt
      )
      is_in_gts = np.stack([l_, t_, r_, b_], axis=1).min(axis=1) > 0.01
      is_pos = is_pos & is_in_gts
  
      # if an anchor box is assigned to multiple gts,
      # the one with the highest IoU will be selected.
      overlaps_inf = -np.inf * np.ones_like(overlaps).T.reshape(-1)
      index = candidate_idxs.reshape(-1)[is_pos.reshape(-1)]
      overlaps_inf[index] = overlaps.T.reshape(-1)[index]
      overlaps_inf = overlaps_inf.reshape(num_gt, -1).T
  
      max_overlaps = overlaps_inf.max(axis=1)
      argmax_overlaps = overlaps_inf.argmax(axis=1)
      assigned_gt_inds[max_overlaps != -np.inf] = (
          argmax_overlaps[max_overlaps != -np.inf] + 1
      )
  
      return assigned_gt_inds, max_overlaps
  
file_path: PaddleDetection/ppdet/data/transform/atss_assigner.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import numpy
  from ppdet.utils.logger import setup_logger
label_desc: Use image node_id 2 for calling the ATSSAssigner obj's underlying member method code with example usage: obj.__call__(bboxes, num_level_bboxes, gt_bboxes, gt_bboxes_ignore, gt_labels) and returns: assigned_gt_inds,  max_overlaps, assigned_gt_inds,  max_overlaps