class_docstr: Anchor-free head used in `FCOS <https://arxiv.org/abs/1904.01355>`_.
  
  The FCOS head does not use anchor boxes. Instead bounding boxes are
  predicted at each pixel and a centerness measure is used to supress
  low-quality predictions.
  Here norm_on_bbox, centerness_on_reg, dcn_on_last_conv are training
  tricks used in official repo, which will bring remarkable mAP gains
  of up to 4.9. Please see https://github.com/tianzhi0549/FCOS for
  more detail.
  
  Args:
      num_classes (int): Number of categories excluding the background
          category.
      in_channels (int): Number of channels in the input feature map.
      strides (list[int] | list[tuple[int, int]]): Strides of points
          in multiple feature levels. Default: (4, 8, 16, 32, 64).
      regress_ranges (tuple[tuple[int, int]]): Regress range of multiple
          level points.
      center_sampling (bool): If true, use center sampling. Default: False.
      center_sample_radius (float): Radius of center sampling. Default: 1.5.
      norm_on_bbox (bool): If true, normalize the regression targets
          with FPN strides. Default: False.
      centerness_on_reg (bool): If true, position centerness on the
          regress branch. Please refer to https://github.com/tianzhi0549/FCOS/issues/89#issuecomment-516877042.
          Default: False.
      conv_bias (bool | str): If specified as `auto`, it will be decided by the
          norm_cfg. Bias of conv will be set as True if `norm_cfg` is None, otherwise
          False. Default: "auto".
      loss_cls (dict): Config of classification loss.
      loss_bbox (dict): Config of localization loss.
      loss_centerness (dict): Config of centerness loss.
      norm_cfg (dict): dictionary to construct and config norm layer.
          Default: norm_cfg=dict(type='GN', num_groups=32, requires_grad=True).
  
  Example:
      >>> self = FCOSHead(11, 7)
      >>> feats = [torch.rand(1, 7, s, s) for s in [4, 8, 16, 32, 64]]
      >>> cls_score, bbox_pred, centerness = self.forward(feats)
      >>> assert len(cls_score) == len(self.scales)
class_docstr_tok: ["Anchor-free","head","used","in","`","FCOS","<","https",":","\/\/arxiv.org\/abs\/1904.01355",">","`","_",".","The","FCOS","head","does","not","use","anchor","boxes",".","Instead","bounding","boxes","are","predicted","at","each","pixel","and","a","centerness","measure","is","used","to","supress","low-quality","predictions",".","Here","norm_on_bbox",",","centerness_on_reg",",","dcn_on_last_conv","are","training","tricks","used","in","official","repo",",","which","will","bring","remarkable","mAP","gains","of","up","to","4.9",".","Please","see","https",":","\/\/github.com\/tianzhi0549\/FCOS","for","more","detail",".","Args",":","num_classes","(","int",")",":","Number","of","categories","excluding","the","background","category",".","in_channels","(","int",")",":","Number","of","channels","in","the","input","feature","map",".","strides","(","list","[","int","]","|","list","[","tuple","[","int",",","int","]","]",")",":","Strides","of","points","in","multiple","feature","levels",".","Default",":","(","4",",","8",",","16",",","32",",","64",")",".","regress_ranges","(","tuple","[","tuple","[","int",",","int","]","]",")",":","Regress","range","of","multiple","level","points",".","center_sampling","(","bool",")",":","If","true",",","use","center","sampling",".","Default",":","False",".","center_sample_radius","(","float",")",":","Radius","of","center","sampling",".","Default",":","1.5.","norm_on_bbox","(","bool",")",":","If","true",",","normalize","the","regression","targets","with","FPN","strides",".","Default",":","False",".","centerness_on_reg","(","bool",")",":","If","true",",","position","centerness","on","the","regress","branch",".","Please","refer","to","https",":","\/\/github.com\/tianzhi0549\/FCOS\/issues\/89","#","issuecomment-516877042",".","Default",":","False",".","conv_bias","(","bool","|","str",")",":","If","specified","as","`","auto","`",",","it","will","be","decided","by","the","norm_cfg",".","Bias","of","conv","will","be","set","as","True","if","`","norm_cfg","`","is","None",",","otherwise","False",".","Default",":","``","auto","''",".","loss_cls","(","dict",")",":","Config","of","classification","loss",".","loss_bbox","(","dict",")",":","Config","of","localization","loss",".","loss_centerness","(","dict",")",":","Config","of","centerness","loss",".","norm_cfg","(","dict",")",":","dictionary","to","construct","and","config","norm","layer",".","Default",":","norm_cfg=dict","(","type='GN","'",",","num_groups=32",",","requires_grad=True",")",".","Example",":",">",">",">","self","=","FCOSHead","(","11",",","7",")",">",">",">","feats","=","[","torch.rand","(","1",",","7",",","s",",","s",")","for","s","in","[","4",",","8",",","16",",","32",",","64","]","]",">",">",">","cls_score",",","bbox_pred",",","centerness","=","self.forward","(","feats",")",">",">",">","assert","len","(","cls_score",")","==","len","(","self.scales",")"]
docstr: Transform outputs for a single batch item into bbox predictions.
  
  Args:
      cls_scores (list[Tensor]): Box scores for a single scale level
          with shape (num_points * num_classes, H, W).
      bbox_preds (list[Tensor]): Box energies / deltas for a single scale
          level with shape (num_points * 4, H, W).
      centernesses (list[Tensor]): Centerness for a single scale level
          with shape (num_points * 4, H, W).
      mlvl_points (list[Tensor]): Box reference for a single scale level
          with shape (num_total_points, 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","bbox","predictions",".","Args",":","cls_scores","(","list","[","Tensor","]",")",":","Box","scores","for","a","single","scale","level","with","shape","(","num_points","*","num_classes",",","H",",","W",")",".","bbox_preds","(","list","[","Tensor","]",")",":","Box","energies","\/","deltas","for","a","single","scale","level","with","shape","(","num_points","*","4",",","H",",","W",")",".","centernesses","(","list","[","Tensor","]",")",":","Centerness","for","a","single","scale","level","with","shape","(","num_points","*","4",",","H",",","W",")",".","mlvl_points","(","list","[","Tensor","]",")",":","Box","reference","for","a","single","scale","level","with","shape","(","num_total_points",",","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_points,
      img_shape,
      scale_factor,
      cfg,
      rescale=False,
      with_nms=True,
  ):
      """Transform outputs for a single batch item into bbox predictions.
  
      Args:
          cls_scores (list[Tensor]): Box scores for a single scale level
              with shape (num_points * num_classes, H, W).
          bbox_preds (list[Tensor]): Box energies / deltas for a single scale
              level with shape (num_points * 4, H, W).
          centernesses (list[Tensor]): Centerness for a single scale level
              with shape (num_points * 4, H, W).
          mlvl_points (list[Tensor]): Box reference for a single scale level
              with shape (num_total_points, 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.
      """
      cfg = self.test_cfg if cfg is None else cfg
      assert len(cls_scores) == len(bbox_preds) == len(mlvl_points)
      mlvl_bboxes = []
      mlvl_scores = []
      mlvl_centerness = []
      for cls_score, bbox_pred, centerness, points in zip(
          cls_scores, bbox_preds, centernesses, mlvl_points
      ):
          assert cls_score.size()[-2:] == bbox_pred.size()[-2:]
          scores = (
              cls_score.permute(1, 2, 0)
              .reshape(-1, self.cls_out_channels)
              .sigmoid()
          )
          centerness = centerness.permute(1, 2, 0).reshape(-1).sigmoid()
  
          bbox_pred = bbox_pred.permute(1, 2, 0).reshape(-1, 4)
          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)
              points = points[topk_inds, :]
              bbox_pred = bbox_pred[topk_inds, :]
              scores = scores[topk_inds, :]
              centerness = centerness[topk_inds]
          bboxes = distance2bbox(points, 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)
      padding = mlvl_scores.new_zeros(mlvl_scores.shape[0], 1)
      # remind that we set FG labels to [0, num_class-1] since mmdet v2.0
      # BG cat_id: num_class
      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
  import torch.nn.functional
  from mmcv.cnn import Scale, normal_init
  from mmcv.runner import force_fp32
  from mmdet.core import distance2bbox, multi_apply, multiclass_nms
  from ..builder import HEADS, build_loss
  from .anchor_free_head import AnchorFreeHead
label_desc: Use image node_id 8 for calling the FCOSHead obj's underlying member method code with example usage: obj._get_bboxes_single(cls_scores, bbox_preds, centernesses, mlvl_points, img_shape, scale_factor, cfg, rescale, with_nms) and returns: det_bboxes,  det_labels, mlvl_bboxes,  mlvl_scores,  mlvl_centerness