class_docstr: Assign a corresponding gt bbox or background to each bbox.
  
  Each proposals will be assigned with `-1`, or a semi-positive integer
  indicating the ground truth index.
  
  - -1: negative sample, no assigned gt
  - semi-positive integer: positive sample, index (0-based) of assigned gt
  
  Args:
      pos_iou_thr (float): IoU threshold for positive bboxes.
      neg_iou_thr (float or tuple): IoU threshold for negative bboxes.
      min_pos_iou (float): Minimum iou for a bbox to be considered as a
          positive bbox. Positive samples can have smaller IoU than
          pos_iou_thr due to the 4th step (assign max IoU sample to each gt).
      gt_max_assign_all (bool): Whether to assign all bboxes with the same
          highest overlap with some gt to that gt.
      ignore_iof_thr (float): IoF threshold for ignoring bboxes (if
          `gt_bboxes_ignore` is specified). Negative values mean not
          ignoring any bboxes.
      ignore_wrt_candidates (bool): Whether to compute the iof between
          `bboxes` and `gt_bboxes_ignore`, or the contrary.
      match_low_quality (bool): Whether to allow low quality matches. This is
          usually allowed for RPN and single stage detectors, but not allowed
          in the second stage. Details are demonstrated in Step 4.
      gpu_assign_thr (int): The upper bound of the number of GT for GPU
          assign. When the number of gt is above this threshold, will assign
          on CPU device. Negative values mean not assign on CPU.
docstr: Assign gt to bboxes.
  
  This method assign a gt bbox to every bbox (proposal/anchor), each bbox
  will be assigned with -1, or a semi-positive number. -1 means negative
  sample, semi-positive number is the index (0-based) of assigned gt.
  The assignment is done in following steps, the order matters.
  
  1. assign every bbox to the background
  2. assign proposals whose iou with all gts < neg_iou_thr to 0
  3. for each bbox, if the iou with its nearest gt >= pos_iou_thr,
     assign it to that bbox
  4. for each gt bbox, assign its nearest proposals (may be more than
     one) to itself
  
  Args:
      bboxes (Tensor): Bounding boxes to be assigned, shape(n, 4).
      gt_bboxes (Tensor): Groundtruth boxes, shape (k, 4).
      gt_bboxes_ignore (Tensor, optional): Ground truth bboxes that are
          labelled as `ignored`, e.g., crowd boxes in COCO.
      gt_labels (Tensor, optional): Label of gt_bboxes, shape (k, ).
  
  Returns:
      :obj:`AssignResult`: The assign result.
  
  Example:
      >>> self = MaxIoUAssigner(0.5, 0.5)
      >>> bboxes = torch.Tensor([[0, 0, 10, 10], [10, 10, 20, 20]])
      >>> gt_bboxes = torch.Tensor([[0, 0, 10, 9]])
      >>> assign_result = self.assign(bboxes, gt_bboxes)
      >>> expected_gt_inds = torch.LongTensor([1, 0])
      >>> assert torch.all(assign_result.gt_inds == expected_gt_inds)
docstr_tok: ["Assign","gt","to","bboxes",".","This","method","assign","a","gt","bbox","to","every","bbox","(","proposal\/anchor",")",",","each","bbox","will","be","assigned","with","-1",",","or","a","semi-positive","number",".","-1","means","negative","sample",",","semi-positive","number","is","the","index","(","0-based",")","of","assigned","gt",".","The","assignment","is","done","in","following","steps",",","the","order","matters",".","1.","assign","every","bbox","to","the","background","2.","assign","proposals","whose","iou","with","all","gts","<","neg_iou_thr","to","0","3.","for","each","bbox",",","if","the","iou","with","its","nearest","gt",">","=","pos_iou_thr",",","assign","it","to","that","bbox","4.","for","each","gt","bbox",",","assign","its","nearest","proposals","(","may","be","more","than","one",")","to","itself","Args",":","bboxes","(","Tensor",")",":","Bounding","boxes","to","be","assigned",",","shape","(","n",",","4",")",".","gt_bboxes","(","Tensor",")",":","Groundtruth","boxes",",","shape","(","k",",","4",")",".","gt_bboxes_ignore","(","Tensor",",","optional",")",":","Ground","truth","bboxes","that","are","labelled","as","`","ignored","`",",","e.g.",",","crowd","boxes","in","COCO",".","gt_labels","(","Tensor",",","optional",")",":","Label","of","gt_bboxes",",","shape","(","k",",",")",".","Returns",":",":","obj",":","`","AssignResult","`",":","The","assign","result",".","Example",":",">",">",">","self","=","MaxIoUAssigner","(","0.5",",","0.5",")",">",">",">","bboxes","=","torch.Tensor","(","[","[","0",",","0",",","10",",","10","]",",","[","10",",","10",",","20",",","20","]","]",")",">",">",">","gt_bboxes","=","torch.Tensor","(","[","[","0",",","0",",","10",",","9","]","]",")",">",">",">","assign_result","=","self.assign","(","bboxes",",","gt_bboxes",")",">",">",">","expected_gt_inds","=","torch.LongTensor","(","[","1",",","0","]",")",">",">",">","assert","torch.all","(","assign_result.gt_inds","==","expected_gt_inds",")"]
code: def assign(
      self, bboxes, gt_bboxes, gt_bboxes_ignore=None, gt_labels=None
  ):
      """Assign gt to bboxes.
  
      This method assign a gt bbox to every bbox (proposal/anchor), each bbox
      will be assigned with -1, or a semi-positive number. -1 means negative
      sample, semi-positive number is the index (0-based) of assigned gt.
      The assignment is done in following steps, the order matters.
  
      1. assign every bbox to the background
      2. assign proposals whose iou with all gts < neg_iou_thr to 0
      3. for each bbox, if the iou with its nearest gt >= pos_iou_thr,
         assign it to that bbox
      4. for each gt bbox, assign its nearest proposals (may be more than
         one) to itself
  
      Args:
          bboxes (Tensor): Bounding boxes to be assigned, shape(n, 4).
          gt_bboxes (Tensor): Groundtruth boxes, shape (k, 4).
          gt_bboxes_ignore (Tensor, optional): Ground truth bboxes that are
              labelled as `ignored`, e.g., crowd boxes in COCO.
          gt_labels (Tensor, optional): Label of gt_bboxes, shape (k, ).
  
      Returns:
          :obj:`AssignResult`: The assign result.
  
      Example:
          >>> self = MaxIoUAssigner(0.5, 0.5)
          >>> bboxes = torch.Tensor([[0, 0, 10, 10], [10, 10, 20, 20]])
          >>> gt_bboxes = torch.Tensor([[0, 0, 10, 9]])
          >>> assign_result = self.assign(bboxes, gt_bboxes)
          >>> expected_gt_inds = torch.LongTensor([1, 0])
          >>> assert torch.all(assign_result.gt_inds == expected_gt_inds)
      """
      assign_on_cpu = (
          True
          if (self.gpu_assign_thr > 0)
          and (gt_bboxes.shape[0] > self.gpu_assign_thr)
          else False
      )
      # compute overlap and assign gt on CPU when number of GT is large
      if assign_on_cpu:
          device = bboxes.device
          bboxes = bboxes.cpu()
          gt_bboxes = gt_bboxes.cpu()
          if gt_bboxes_ignore is not None:
              gt_bboxes_ignore = gt_bboxes_ignore.cpu()
          if gt_labels is not None:
              gt_labels = gt_labels.cpu()
  
      overlaps = self.iou_calculator(gt_bboxes, bboxes)
  
      if (
          self.ignore_iof_thr > 0
          and gt_bboxes_ignore is not None
          and gt_bboxes_ignore.numel() > 0
          and bboxes.numel() > 0
      ):
          if self.ignore_wrt_candidates:
              ignore_overlaps = self.iou_calculator(
                  bboxes, gt_bboxes_ignore, mode="iof"
              )
              ignore_max_overlaps, _ = ignore_overlaps.max(dim=1)
          else:
              ignore_overlaps = self.iou_calculator(
                  gt_bboxes_ignore, bboxes, mode="iof"
              )
              ignore_max_overlaps, _ = ignore_overlaps.max(dim=0)
          overlaps[:, ignore_max_overlaps > self.ignore_iof_thr] = -1
  
      assign_result = self.assign_wrt_overlaps(overlaps, gt_labels)
      if assign_on_cpu:
          assign_result.gt_inds = assign_result.gt_inds.to(device)
          assign_result.max_overlaps = assign_result.max_overlaps.to(
              device
          )
          if assign_result.labels is not None:
              assign_result.labels = assign_result.labels.to(device)
      return assign_result
  
file_path: insightface/detection/scrfd/mmdet/core/bbox/assigners/max_iou_assigner.py
imports: import torch
  from ..builder import BBOX_ASSIGNERS
  from ..iou_calculators import build_iou_calculator
  from .assign_result import AssignResult
  from .base_assigner import BaseAssigner
label_desc: Use image node_id 2 for calling the MaxIoUAssigner obj's underlying member method code with example usage: obj.assign(bboxes, gt_bboxes, gt_bboxes_ignore, gt_labels) and returns: assign_result