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: Compute regression and classification targets for a single image.
docstr_tok: ["Compute","regression","and","classification","targets","for","a","single","image","."]
code: def _get_target_single(
      self,
      gt_bboxes,
      gt_labels,
      points,
      regress_ranges,
      num_points_per_lvl,
  ):
      """Compute regression and classification targets for a single image."""
      num_points = points.size(0)
      num_gts = gt_labels.size(0)
      if num_gts == 0:
          return gt_labels.new_full(
              (num_points,), self.num_classes
          ), gt_bboxes.new_zeros((num_points, 4))
  
      areas = (gt_bboxes[:, 2] - gt_bboxes[:, 0]) * (
          gt_bboxes[:, 3] - gt_bboxes[:, 1]
      )
      # TODO: figure out why these two are different
      # areas = areas[None].expand(num_points, num_gts)
      areas = areas[None].repeat(num_points, 1)
      regress_ranges = regress_ranges[:, None, :].expand(
          num_points, num_gts, 2
      )
      gt_bboxes = gt_bboxes[None].expand(num_points, num_gts, 4)
      xs, ys = points[:, 0], points[:, 1]
      xs = xs[:, None].expand(num_points, num_gts)
      ys = ys[:, None].expand(num_points, num_gts)
  
      left = xs - gt_bboxes[..., 0]
      right = gt_bboxes[..., 2] - xs
      top = ys - gt_bboxes[..., 1]
      bottom = gt_bboxes[..., 3] - ys
      bbox_targets = torch.stack((left, top, right, bottom), -1)
  
      if self.center_sampling:
          # condition1: inside a `center bbox`
          radius = self.center_sample_radius
          center_xs = (gt_bboxes[..., 0] + gt_bboxes[..., 2]) / 2
          center_ys = (gt_bboxes[..., 1] + gt_bboxes[..., 3]) / 2
          center_gts = torch.zeros_like(gt_bboxes)
          stride = center_xs.new_zeros(center_xs.shape)
  
          # project the points on current lvl back to the `original` sizes
          lvl_begin = 0
          for lvl_idx, num_points_lvl in enumerate(num_points_per_lvl):
              lvl_end = lvl_begin + num_points_lvl
              stride[lvl_begin:lvl_end] = self.strides[lvl_idx] * radius
              lvl_begin = lvl_end
  
          x_mins = center_xs - stride
          y_mins = center_ys - stride
          x_maxs = center_xs + stride
          y_maxs = center_ys + stride
          center_gts[..., 0] = torch.where(
              x_mins > gt_bboxes[..., 0], x_mins, gt_bboxes[..., 0]
          )
          center_gts[..., 1] = torch.where(
              y_mins > gt_bboxes[..., 1], y_mins, gt_bboxes[..., 1]
          )
          center_gts[..., 2] = torch.where(
              x_maxs > gt_bboxes[..., 2], gt_bboxes[..., 2], x_maxs
          )
          center_gts[..., 3] = torch.where(
              y_maxs > gt_bboxes[..., 3], gt_bboxes[..., 3], y_maxs
          )
  
          cb_dist_left = xs - center_gts[..., 0]
          cb_dist_right = center_gts[..., 2] - xs
          cb_dist_top = ys - center_gts[..., 1]
          cb_dist_bottom = center_gts[..., 3] - ys
          center_bbox = torch.stack(
              (
                  cb_dist_left,
                  cb_dist_top,
                  cb_dist_right,
                  cb_dist_bottom,
              ),
              -1,
          )
          inside_gt_bbox_mask = center_bbox.min(-1)[0] > 0
      else:
          # condition1: inside a gt bbox
          inside_gt_bbox_mask = bbox_targets.min(-1)[0] > 0
  
      # condition2: limit the regression range for each location
      max_regress_distance = bbox_targets.max(-1)[0]
      inside_regress_range = (
          max_regress_distance >= regress_ranges[..., 0]
      ) & (max_regress_distance <= regress_ranges[..., 1])
  
      # if there are still more than one objects for a location,
      # we choose the one with minimal area
      areas[inside_gt_bbox_mask == 0] = INF
      areas[inside_regress_range == 0] = INF
      min_area, min_area_inds = areas.min(dim=1)
  
      labels = gt_labels[min_area_inds]
      labels[min_area == INF] = self.num_classes  # set as BG
      bbox_targets = bbox_targets[range(num_points), min_area_inds]
  
      return labels, bbox_targets
  
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 11 for calling the FCOSHead obj's underlying member method code with example usage: obj._get_target_single(gt_bboxes, gt_labels, points, regress_ranges, num_points_per_lvl) and returns: labels,  bbox_targets, gt_labels,  gt_bboxes