class_docstr: Bridging the Gap Between Anchor-based and Anchor-free Detection via
  Adaptive Training Sample Selection.
  
  ATSS head structure is similar with FCOS, however ATSS use anchor boxes
  and assign label by Adaptive Training Sample Selection instead max-iou.
  
  https://arxiv.org/abs/1912.02424
class_docstr_tok: ["Bridging","the","Gap","Between","Anchor-based","and","Anchor-free","Detection","via","Adaptive","Training","Sample","Selection",".","ATSS","head","structure","is","similar","with","FCOS",",","however","ATSS","use","anchor","boxes","and","assign","label","by","Adaptive","Training","Sample","Selection","instead","max-iou",".","https",":","\/\/arxiv.org\/abs\/1912.02424"]
docstr: Transform outputs for a single batch item into labeled boxes.
  
  Args:
      cls_scores (list[Tensor]): Box scores for a single scale level
          with shape (num_anchors * num_classes, H, W).
      bbox_preds (list[Tensor]): Box energies / deltas for a single
          scale level with shape (num_anchors * 4, H, W).
      centernesses (list[Tensor]): Centerness for a single scale level
          with shape (num_anchors * 1, H, W).
      mlvl_anchors (list[Tensor]): Box reference for a single scale level
          with shape (num_total_anchors, 4).
      img_shape (tuple[int]): Shape of the input image,
          (height, width, 3).
      scale_factor (ndarray): Scale factor of the image arrange as
          (w_scale, h_scale, w_scale, h_scale).
      cfg (mmcv.Config | None): Test / postprocessing configuration,
          if None, test_cfg would be used.
      rescale (bool): If True, return boxes in original image space.
          Default: False.
      with_nms (bool): If True, do nms before return boxes.
          Default: True.
  
  Returns:
      tuple(Tensor):
          det_bboxes (Tensor): BBox predictions in shape (n, 5), where
              the first 4 columns are bounding box positions
              (tl_x, tl_y, br_x, br_y) and the 5-th column is a score
              between 0 and 1.
          det_labels (Tensor): A (n,) tensor where each item is the
              predicted class label of the corresponding box.
docstr_tok: ["Transform","outputs","for","a","single","batch","item","into","labeled","boxes",".","Args",":","cls_scores","(","list","[","Tensor","]",")",":","Box","scores","for","a","single","scale","level","with","shape","(","num_anchors","*","num_classes",",","H",",","W",")",".","bbox_preds","(","list","[","Tensor","]",")",":","Box","energies","\/","deltas","for","a","single","scale","level","with","shape","(","num_anchors","*","4",",","H",",","W",")",".","centernesses","(","list","[","Tensor","]",")",":","Centerness","for","a","single","scale","level","with","shape","(","num_anchors","*","1",",","H",",","W",")",".","mlvl_anchors","(","list","[","Tensor","]",")",":","Box","reference","for","a","single","scale","level","with","shape","(","num_total_anchors",",","4",")",".","img_shape","(","tuple","[","int","]",")",":","Shape","of","the","input","image",",","(","height",",","width",",","3",")",".","scale_factor","(","ndarray",")",":","Scale","factor","of","the","image","arrange","as","(","w_scale",",","h_scale",",","w_scale",",","h_scale",")",".","cfg","(","mmcv.Config","|","None",")",":","Test","\/","postprocessing","configuration",",","if","None",",","test_cfg","would","be","used",".","rescale","(","bool",")",":","If","True",",","return","boxes","in","original","image","space",".","Default",":","False",".","with_nms","(","bool",")",":","If","True",",","do","nms","before","return","boxes",".","Default",":","True",".","Returns",":","tuple","(","Tensor",")",":","det_bboxes","(","Tensor",")",":","BBox","predictions","in","shape","(","n",",","5",")",",","where","the","first","4","columns","are","bounding","box","positions","(","tl_x",",","tl_y",",","br_x",",","br_y",")","and","the","5-th","column","is","a","score","between","0","and","1.","det_labels","(","Tensor",")",":","A","(","n",",",")","tensor","where","each","item","is","the","predicted","class","label","of","the","corresponding","box","."]
code: def _get_bboxes_single(
      self,
      cls_scores,
      bbox_preds,
      centernesses,
      mlvl_anchors,
      img_shape,
      scale_factor,
      cfg,
      rescale=False,
      with_nms=True,
  ):
      """Transform outputs for a single batch item into labeled boxes.
  
      Args:
          cls_scores (list[Tensor]): Box scores for a single scale level
              with shape (num_anchors * num_classes, H, W).
          bbox_preds (list[Tensor]): Box energies / deltas for a single
              scale level with shape (num_anchors * 4, H, W).
          centernesses (list[Tensor]): Centerness for a single scale level
              with shape (num_anchors * 1, H, W).
          mlvl_anchors (list[Tensor]): Box reference for a single scale level
              with shape (num_total_anchors, 4).
          img_shape (tuple[int]): Shape of the input image,
              (height, width, 3).
          scale_factor (ndarray): Scale factor of the image arrange as
              (w_scale, h_scale, w_scale, h_scale).
          cfg (mmcv.Config | None): Test / postprocessing configuration,
              if None, test_cfg would be used.
          rescale (bool): If True, return boxes in original image space.
              Default: False.
          with_nms (bool): If True, do nms before return boxes.
              Default: True.
  
      Returns:
          tuple(Tensor):
              det_bboxes (Tensor): BBox predictions in shape (n, 5), where
                  the first 4 columns are bounding box positions
                  (tl_x, tl_y, br_x, br_y) and the 5-th column is a score
                  between 0 and 1.
              det_labels (Tensor): A (n,) tensor where each item is the
                  predicted class label of the corresponding box.
      """
      assert len(cls_scores) == len(bbox_preds) == len(mlvl_anchors)
      mlvl_bboxes = []
      mlvl_scores = []
      mlvl_centerness = []
      for cls_score, bbox_pred, centerness, anchors in zip(
          cls_scores, bbox_preds, centernesses, mlvl_anchors
      ):
          assert cls_score.size()[-2:] == bbox_pred.size()[-2:]
  
          scores = (
              cls_score.permute(1, 2, 0)
              .reshape(-1, self.cls_out_channels)
              .sigmoid()
          )
          bbox_pred = bbox_pred.permute(1, 2, 0).reshape(-1, 4)
          centerness = centerness.permute(1, 2, 0).reshape(-1).sigmoid()
  
          nms_pre = cfg.get("nms_pre", -1)
          if nms_pre > 0 and scores.shape[0] > nms_pre:
              max_scores, _ = (scores * centerness[:, None]).max(dim=1)
              _, topk_inds = max_scores.topk(nms_pre)
              anchors = anchors[topk_inds, :]
              bbox_pred = bbox_pred[topk_inds, :]
              scores = scores[topk_inds, :]
              centerness = centerness[topk_inds]
  
          bboxes = self.bbox_coder.decode(
              anchors, bbox_pred, max_shape=img_shape
          )
          mlvl_bboxes.append(bboxes)
          mlvl_scores.append(scores)
          mlvl_centerness.append(centerness)
  
      mlvl_bboxes = torch.cat(mlvl_bboxes)
      if rescale:
          mlvl_bboxes /= mlvl_bboxes.new_tensor(scale_factor)
      mlvl_scores = torch.cat(mlvl_scores)
      # Add a dummy background class to the backend when using sigmoid
      # remind that we set FG labels to [0, num_class-1] since mmdet v2.0
      # BG cat_id: num_class
      padding = mlvl_scores.new_zeros(mlvl_scores.shape[0], 1)
      mlvl_scores = torch.cat([mlvl_scores, padding], dim=1)
      mlvl_centerness = torch.cat(mlvl_centerness)
  
      if with_nms:
          det_bboxes, det_labels = multiclass_nms(
              mlvl_bboxes,
              mlvl_scores,
              cfg.score_thr,
              cfg.nms,
              cfg.max_per_img,
              score_factors=mlvl_centerness,
          )
          return det_bboxes, det_labels
      else:
          return mlvl_bboxes, mlvl_scores, mlvl_centerness
  
imports: import torch
  import torch.nn
  from mmcv.cnn import ConvModule, Scale, bias_init_with_prob, normal_init
  from mmcv.runner import force_fp32
  from mmdet.core import anchor_inside_flags, build_assigner, build_sampler, images_to_levels, multi_apply, multiclass_nms, reduce_mean, unmap
  from ..builder import HEADS, build_loss
  from .anchor_head import AnchorHead
label_desc: Use image node_id 10 for calling the ATSSHead obj's underlying member method code with example usage: obj._get_bboxes_single(cls_scores, bbox_preds, centernesses, mlvl_anchors, img_shape, scale_factor, cfg, rescale, with_nms) and returns: det_bboxes,  det_labels, mlvl_bboxes,  mlvl_scores,  mlvl_centerness