class_docstr: TOODHead used in `TOOD: Task-aligned One-stage Object Detection.
  
  <https://arxiv.org/abs/2108.07755>`_.
  
  TOOD uses Task-aligned head (T-head) and is optimized by Task Alignment
  Learning (TAL).
  
  Args:
      num_classes (int): Number of categories excluding the background
          category.
      in_channels (int): Number of channels in the input feature map.
      num_dcn (int): Number of deformable convolution in the head.
          Defaults to 0.
      anchor_type (str): If set to ``anchor_free``, the head will use centers
          to regress bboxes. If set to ``anchor_based``, the head will
          regress bboxes based on anchors. Defaults to ``anchor_free``.
      initial_loss_cls (:obj:`ConfigDict` or dict): Config of initial loss.
  
  Example:
      >>> self = TOODHead(11, 7)
      >>> feats = [torch.rand(1, 7, s, s) for s in [4, 8, 16, 32, 64]]
      >>> cls_score, bbox_pred = self.forward(feats)
      >>> assert len(cls_score) == len(self.scales)
class_docstr_tok: ["TOODHead","used","in","`","TOOD",":","Task-aligned","One-stage","Object","Detection",".","<","https",":","\/\/arxiv.org\/abs\/2108.07755",">","`","_",".","TOOD","uses","Task-aligned","head","(","T-head",")","and","is","optimized","by","Task","Alignment","Learning","(","TAL",")",".","Args",":","num_classes","(","int",")",":","Number","of","categories","excluding","the","background","category",".","in_channels","(","int",")",":","Number","of","channels","in","the","input","feature","map",".","num_dcn","(","int",")",":","Number","of","deformable","convolution","in","the","head",".","Defaults","to","0.","anchor_type","(","str",")",":","If","set","to","``","anchor_free","``",",","the","head","will","use","centers","to","regress","bboxes",".","If","set","to","``","anchor_based","``",",","the","head","will","regress","bboxes","based","on","anchors",".","Defaults","to","``","anchor_free","``",".","initial_loss_cls","(",":","obj",":","`","ConfigDict","`","or","dict",")",":","Config","of","initial","loss",".","Example",":",">",">",">","self","=","TOODHead","(","11",",","7",")",">",">",">","feats","=","[","torch.rand","(","1",",","7",",","s",",","s",")","for","s","in","[","4",",","8",",","16",",","32",",","64","]","]",">",">",">","cls_score",",","bbox_pred","=","self.forward","(","feats",")",">",">",">","assert","len","(","cls_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, each item has shape
          (num_priors * 1, H, W).
      mlvl_priors (list[Tensor]): Each element in the list is
          the priors of a single level in feature pyramid. In all
          anchor-based methods, it has shape (num_priors, 4). In
          all anchor-free methods, it has shape (num_priors, 2)
          when `with_stride=True`, otherwise it still has shape
          (num_priors, 4).
      img_meta (dict): Image meta info.
      cfg (:obj:`ConfigDict`, optional): 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",",","each","item","has","shape","(","num_priors","*","1",",","H",",","W",")",".","mlvl_priors","(","list","[","Tensor","]",")",":","Each","element","in","the","list","is","the","priors","of","a","single","level","in","feature","pyramid",".","In","all","anchor-based","methods",",","it","has","shape","(","num_priors",",","4",")",".","In","all","anchor-free","methods",",","it","has","shape","(","num_priors",",","2",")","when","`","with_stride=True","`",",","otherwise","it","still","has","shape","(","num_priors",",","4",")",".","img_meta","(","dict",")",":","Image","meta","info",".","cfg","(",":","obj",":","`","ConfigDict","`",",","optional",")",":","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: Optional[ConfigDict] = None,
      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, each item has shape
                  (num_priors * 1, H, W).
              mlvl_priors (list[Tensor]): Each element in the list is
                  the priors of a single level in feature pyramid. In all
                  anchor-based methods, it has shape (num_priors, 4). In
                  all anchor-free methods, it has shape (num_priors, 2)
                  when `with_stride=True`, otherwise it still has shape
                  (num_priors, 4).
              img_meta (dict): Image meta info.
              cfg (:obj:`ConfigDict`, optional): 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
      nms_pre = cfg.get("nms_pre", -1)
  
      mlvl_bboxes = []
      mlvl_scores = []
      mlvl_labels = []
      for cls_score, bbox_pred, priors, stride in zip(
          cls_score_list,
          bbox_pred_list,
          mlvl_priors,
          self.prior_generator.strides,
      ):
          assert cls_score.size()[-2:] == bbox_pred.size()[-2:]
  
          bbox_pred = (
              bbox_pred.permute(1, 2, 0).reshape(-1, 4) * stride[0]
          )
          scores = cls_score.permute(1, 2, 0).reshape(
              -1, self.cls_out_channels
          )
  
          # 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, keep_idxs, filtered_results = results
  
          bboxes = filtered_results["bbox_pred"]
  
          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, Tuple
  import torch
  import torch.nn
  import torch.nn.functional
  from mmcv.cnn import ConvModule, Scale
  from mmcv.ops import deform_conv2d
  from mmengine import MessageHub
  from mmengine.config import ConfigDict
  from mmengine.model import bias_init_with_prob, normal_init
  from mmengine.structures import InstanceData
  from torch import Tensor
  from mmdet.registry import MODELS, TASK_UTILS
  from mmdet.structures.bbox import distance2bbox
  from mmdet.utils import ConfigType, InstanceList, OptConfigType, OptInstanceList, reduce_mean
  from ..task_modules.prior_generators import anchor_inside_flags
  from ..utils import filter_scores_and_topk, images_to_levels, multi_apply, sigmoid_geometric_mean, unmap
  from .atss_head import ATSSHead
label_desc: Use image node_id 9 for calling the TOODHead 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