class_docstr: Generalized Focal Loss: Learning Qualified and Distributed Bounding
  Boxes for Dense Object Detection.
  
  GFL head structure is similar with ATSS, however GFL uses
  1) joint representation for classification and localization quality, and
  2) flexible General distribution for bounding box locations,
  which are supervised by
  Quality Focal Loss (QFL) and Distribution Focal Loss (DFL), respectively
  
  https://arxiv.org/abs/2006.04388
  
  Args:
      num_classes (int): Number of categories excluding the background
          category.
      in_channels (int): Number of channels in the input feature map.
      stacked_convs (int): Number of conv layers in cls and reg tower.
          Defaults to 4.
      conv_cfg (:obj:`ConfigDict` or dict, optional): dictionary to construct
          and config conv layer. Defaults to None.
      norm_cfg (:obj:`ConfigDict` or dict): dictionary to construct and
          config norm layer. Default: dict(type='GN', num_groups=32,
          requires_grad=True).
      loss_qfl (:obj:`ConfigDict` or dict): Config of Quality Focal Loss
          (QFL).
      bbox_coder (:obj:`ConfigDict` or dict): Config of bbox coder. Defaults
           to 'DistancePointBBoxCoder'.
      reg_max (int): Max value of integral set :math: ``{0, ..., reg_max}``
          in QFL setting. Defaults to 16.
      init_cfg (:obj:`ConfigDict` or dict or list[dict] or
          list[:obj:`ConfigDict`]): Initialization config dict.
  Example:
      >>> self = GFLHead(11, 7)
      >>> feats = [torch.rand(1, 7, s, s) for s in [4, 8, 16, 32, 64]]
      >>> cls_quality_score, bbox_pred = self.forward(feats)
      >>> assert len(cls_quality_score) == len(self.scales)
class_docstr_tok: ["Generalized","Focal","Loss",":","Learning","Qualified","and","Distributed","Bounding","Boxes","for","Dense","Object","Detection",".","GFL","head","structure","is","similar","with","ATSS",",","however","GFL","uses","1",")","joint","representation","for","classification","and","localization","quality",",","and","2",")","flexible","General","distribution","for","bounding","box","locations",",","which","are","supervised","by","Quality","Focal","Loss","(","QFL",")","and","Distribution","Focal","Loss","(","DFL",")",",","respectively","https",":","\/\/arxiv.org\/abs\/2006.04388","Args",":","num_classes","(","int",")",":","Number","of","categories","excluding","the","background","category",".","in_channels","(","int",")",":","Number","of","channels","in","the","input","feature","map",".","stacked_convs","(","int",")",":","Number","of","conv","layers","in","cls","and","reg","tower",".","Defaults","to","4.","conv_cfg","(",":","obj",":","`","ConfigDict","`","or","dict",",","optional",")",":","dictionary","to","construct","and","config","conv","layer",".","Defaults","to","None",".","norm_cfg","(",":","obj",":","`","ConfigDict","`","or","dict",")",":","dictionary","to","construct","and","config","norm","layer",".","Default",":","dict","(","type='GN","'",",","num_groups=32",",","requires_grad=True",")",".","loss_qfl","(",":","obj",":","`","ConfigDict","`","or","dict",")",":","Config","of","Quality","Focal","Loss","(","QFL",")",".","bbox_coder","(",":","obj",":","`","ConfigDict","`","or","dict",")",":","Config","of","bbox","coder",".","Defaults","to","'DistancePointBBoxCoder","'",".","reg_max","(","int",")",":","Max","value","of","integral","set",":","math",":","``","{","0",",","...",",","reg_max","}","``","in","QFL","setting",".","Defaults","to","16.","init_cfg","(",":","obj",":","`","ConfigDict","`","or","dict","or","list","[","dict","]","or","list","[",":","obj",":","`","ConfigDict","`","]",")",":","Initialization","config","dict",".","Example",":",">",">",">","self","=","GFLHead","(","11",",","7",")",">",">",">","feats","=","[","torch.rand","(","1",",","7",",","s",",","s",")","for","s","in","[","4",",","8",",","16",",","32",",","64","]","]",">",">",">","cls_quality_score",",","bbox_pred","=","self.forward","(","feats",")",">",">",">","assert","len","(","cls_quality_score",")","==","len","(","self.scales",")"]
docstr: Transform a single image's features extracted from the head into
  bbox results.
  
  Args:
      cls_score_list (list[Tensor]): Box scores from all scale
          levels of a single image, each item has shape
          (num_priors * num_classes, H, W).
      bbox_pred_list (list[Tensor]): Box energies / deltas from
          all scale levels of a single image, each item has shape
          (num_priors * 4, H, W).
      score_factor_list (list[Tensor]): Score factor from all scale
          levels of a single image. GFL head does not need this value.
      mlvl_priors (list[Tensor]): Each element in the list is
          the priors of a single level in feature pyramid, has shape
          (num_priors, 4).
      img_meta (dict): Image meta info.
      cfg (:obj: `ConfigDict`): Test / postprocessing configuration,
          if None, test_cfg would be used.
      rescale (bool): If True, return boxes in original image space.
          Defaults to False.
      with_nms (bool): If True, do nms before return boxes.
          Defaults to True.
  
  Returns:
      tuple[Tensor]: Results of detected bboxes and labels. If with_nms
      is False and mlvl_score_factor is None, return mlvl_bboxes and
      mlvl_scores, else return mlvl_bboxes, mlvl_scores and
      mlvl_score_factor. Usually with_nms is False is used for aug
      test. If with_nms is True, then return the following format
  
      - det_bboxes (Tensor): Predicted bboxes with shape
        [num_bboxes, 5], where the first 4 columns are bounding
        box positions (tl_x, tl_y, br_x, br_y) and the 5-th
        column are scores between 0 and 1.
      - det_labels (Tensor): Predicted labels of the corresponding
        box with shape [num_bboxes].
docstr_tok: ["Transform","a","single","image","'s","features","extracted","from","the","head","into","bbox","results",".","Args",":","cls_score_list","(","list","[","Tensor","]",")",":","Box","scores","from","all","scale","levels","of","a","single","image",",","each","item","has","shape","(","num_priors","*","num_classes",",","H",",","W",")",".","bbox_pred_list","(","list","[","Tensor","]",")",":","Box","energies","\/","deltas","from","all","scale","levels","of","a","single","image",",","each","item","has","shape","(","num_priors","*","4",",","H",",","W",")",".","score_factor_list","(","list","[","Tensor","]",")",":","Score","factor","from","all","scale","levels","of","a","single","image",".","GFL","head","does","not","need","this","value",".","mlvl_priors","(","list","[","Tensor","]",")",":","Each","element","in","the","list","is","the","priors","of","a","single","level","in","feature","pyramid",",","has","shape","(","num_priors",",","4",")",".","img_meta","(","dict",")",":","Image","meta","info",".","cfg","(",":","obj",":","`","ConfigDict","`",")",":","Test","\/","postprocessing","configuration",",","if","None",",","test_cfg","would","be","used",".","rescale","(","bool",")",":","If","True",",","return","boxes","in","original","image","space",".","Defaults","to","False",".","with_nms","(","bool",")",":","If","True",",","do","nms","before","return","boxes",".","Defaults","to","True",".","Returns",":","tuple","[","Tensor","]",":","Results","of","detected","bboxes","and","labels",".","If","with_nms","is","False","and","mlvl_score_factor","is","None",",","return","mlvl_bboxes","and","mlvl_scores",",","else","return","mlvl_bboxes",",","mlvl_scores","and","mlvl_score_factor",".","Usually","with_nms","is","False","is","used","for","aug","test",".","If","with_nms","is","True",",","then","return","the","following","format","-","det_bboxes","(","Tensor",")",":","Predicted","bboxes","with","shape","[","num_bboxes",",","5","]",",","where","the","first","4","columns","are","bounding","box","positions","(","tl_x",",","tl_y",",","br_x",",","br_y",")","and","the","5-th","column","are","scores","between","0","and","1",".","-","det_labels","(","Tensor",")",":","Predicted","labels","of","the","corresponding","box","with","shape","[","num_bboxes","]","."]
code: def _predict_by_feat_single(
      self,
      cls_score_list: List[Tensor],
      bbox_pred_list: List[Tensor],
      score_factor_list: List[Tensor],
      mlvl_priors: List[Tensor],
      img_meta: dict,
      cfg: ConfigDict,
      rescale: bool = False,
      with_nms: bool = True,
  ) -> InstanceData:
      """Transform a single image's features extracted from the head into
      bbox results.
  
      Args:
          cls_score_list (list[Tensor]): Box scores from all scale
              levels of a single image, each item has shape
              (num_priors * num_classes, H, W).
          bbox_pred_list (list[Tensor]): Box energies / deltas from
              all scale levels of a single image, each item has shape
              (num_priors * 4, H, W).
          score_factor_list (list[Tensor]): Score factor from all scale
              levels of a single image. GFL head does not need this value.
          mlvl_priors (list[Tensor]): Each element in the list is
              the priors of a single level in feature pyramid, has shape
              (num_priors, 4).
          img_meta (dict): Image meta info.
          cfg (:obj: `ConfigDict`): Test / postprocessing configuration,
              if None, test_cfg would be used.
          rescale (bool): If True, return boxes in original image space.
              Defaults to False.
          with_nms (bool): If True, do nms before return boxes.
              Defaults to True.
  
      Returns:
          tuple[Tensor]: Results of detected bboxes and labels. If with_nms
          is False and mlvl_score_factor is None, return mlvl_bboxes and
          mlvl_scores, else return mlvl_bboxes, mlvl_scores and
          mlvl_score_factor. Usually with_nms is False is used for aug
          test. If with_nms is True, then return the following format
  
          - det_bboxes (Tensor): Predicted bboxes with shape
            [num_bboxes, 5], where the first 4 columns are bounding
            box positions (tl_x, tl_y, br_x, br_y) and the 5-th
            column are scores between 0 and 1.
          - det_labels (Tensor): Predicted labels of the corresponding
            box with shape [num_bboxes].
      """
      cfg = self.test_cfg if cfg is None else cfg
      img_shape = img_meta["img_shape"]
      nms_pre = cfg.get("nms_pre", -1)
  
      mlvl_bboxes = []
      mlvl_scores = []
      mlvl_labels = []
      for level_idx, (
          cls_score,
          bbox_pred,
          stride,
          priors,
      ) in enumerate(
          zip(
              cls_score_list,
              bbox_pred_list,
              self.prior_generator.strides,
              mlvl_priors,
          )
      ):
          assert cls_score.size()[-2:] == bbox_pred.size()[-2:]
          assert stride[0] == stride[1]
  
          bbox_pred = bbox_pred.permute(1, 2, 0)
          bbox_pred = self.integral(bbox_pred) * stride[0]
  
          scores = (
              cls_score.permute(1, 2, 0)
              .reshape(-1, self.cls_out_channels)
              .sigmoid()
          )
  
          # After https://github.com/open-mmlab/mmdetection/pull/6268/,
          # this operation keeps fewer bboxes under the same `nms_pre`.
          # There is no difference in performance for most models. If you
          # find a slight drop in performance, you can set a larger
          # `nms_pre` than before.
          results = filter_scores_and_topk(
              scores,
              cfg.score_thr,
              nms_pre,
              dict(bbox_pred=bbox_pred, priors=priors),
          )
          scores, labels, _, filtered_results = results
  
          bbox_pred = filtered_results["bbox_pred"]
          priors = filtered_results["priors"]
  
          bboxes = self.bbox_coder.decode(
              self.anchor_center(priors), bbox_pred, max_shape=img_shape
          )
          mlvl_bboxes.append(bboxes)
          mlvl_scores.append(scores)
          mlvl_labels.append(labels)
  
      results = InstanceData()
      results.bboxes = torch.cat(mlvl_bboxes)
      results.scores = torch.cat(mlvl_scores)
      results.labels = torch.cat(mlvl_labels)
  
      return self._bbox_post_process(
          results=results,
          cfg=cfg,
          rescale=rescale,
          with_nms=with_nms,
          img_meta=img_meta,
      )
  
imports: from typing import List, Optional, Sequence, Tuple
  import torch
  import torch.nn
  import torch.nn.functional
  from mmcv.cnn import ConvModule, Scale
  from mmengine.config import ConfigDict
  from mmengine.structures import InstanceData
  from torch import Tensor
  from mmdet.registry import MODELS, TASK_UTILS
  from mmdet.structures.bbox import bbox_overlaps
  from mmdet.utils import ConfigType, InstanceList, MultiConfig, OptConfigType, OptInstanceList, reduce_mean
  from ..task_modules.prior_generators import anchor_inside_flags
  from ..task_modules.samplers import PseudoSampler
  from ..utils import filter_scores_and_topk, images_to_levels, multi_apply, unmap
  from .anchor_head import AnchorHead
label_desc: Use image node_id 8 for calling the GFLHead obj's underlying member method code with example usage: obj._predict_by_feat_single(cls_score_list, bbox_pred_list, score_factor_list, mlvl_priors, img_meta, cfg, rescale, with_nms) and returns: self