class_docstr: Guided-Anchor-based head (GA-RPN, GA-RetinaNet, etc.).
  
  This GuidedAnchorHead will predict high-quality feature guided
  anchors and locations where anchors will be kept in inference.
  There are mainly 3 categories of bounding-boxes.
  
  - Sampled 9 pairs for target assignment. (approxes)
  - The square boxes where the predicted anchors are based on. (squares)
  - Guided anchors.
  
  Please refer to https://arxiv.org/abs/1901.03278 for more details.
  
  Args:
      num_classes (int): Number of classes.
      in_channels (int): Number of channels in the input feature map.
      feat_channels (int): Number of hidden channels. Defaults to 256.
      approx_anchor_generator (:obj:`ConfigDict` or dict): Config dict
          for approx generator
      square_anchor_generator (:obj:`ConfigDict` or dict): Config dict
          for square generator
      anchor_coder (:obj:`ConfigDict` or dict): Config dict for anchor coder
      bbox_coder (:obj:`ConfigDict` or dict): Config dict for bbox coder
      reg_decoded_bbox (bool): If true, the regression loss would be
          applied directly on decoded bounding boxes, converting both
          the predicted boxes and regression targets to absolute
          coordinates format. Defaults to False. It should be `True` when
          using `IoULoss`, `GIoULoss`, or `DIoULoss` in the bbox head.
      deform_groups: (int): Group number of DCN in FeatureAdaption module.
          Defaults to 4.
      loc_filter_thr (float): Threshold to filter out unconcerned regions.
          Defaults to 0.01.
      loss_loc (:obj:`ConfigDict` or dict): Config of location loss.
      loss_shape (:obj:`ConfigDict` or dict): Config of anchor shape loss.
      loss_cls (:obj:`ConfigDict` or dict): Config of classification loss.
      loss_bbox (:obj:`ConfigDict` or dict): Config of bbox regression loss.
      init_cfg (:obj:`ConfigDict` or list[:obj:`ConfigDict`] or dict or             list[dict], optional): Initialization config dict.
class_docstr_tok: ["Guided-Anchor-based","head","(","GA-RPN",",","GA-RetinaNet",",","etc.",")",".","This","GuidedAnchorHead","will","predict","high-quality","feature","guided","anchors","and","locations","where","anchors","will","be","kept","in","inference",".","There","are","mainly","3","categories","of","bounding-boxes",".","-","Sampled","9","pairs","for","target","assignment",".","(","approxes",")","-","The","square","boxes","where","the","predicted","anchors","are","based","on",".","(","squares",")","-","Guided","anchors",".","Please","refer","to","https",":","\/\/arxiv.org\/abs\/1901.03278","for","more","details",".","Args",":","num_classes","(","int",")",":","Number","of","classes",".","in_channels","(","int",")",":","Number","of","channels","in","the","input","feature","map",".","feat_channels","(","int",")",":","Number","of","hidden","channels",".","Defaults","to","256.","approx_anchor_generator","(",":","obj",":","`","ConfigDict","`","or","dict",")",":","Config","dict","for","approx","generator","square_anchor_generator","(",":","obj",":","`","ConfigDict","`","or","dict",")",":","Config","dict","for","square","generator","anchor_coder","(",":","obj",":","`","ConfigDict","`","or","dict",")",":","Config","dict","for","anchor","coder","bbox_coder","(",":","obj",":","`","ConfigDict","`","or","dict",")",":","Config","dict","for","bbox","coder","reg_decoded_bbox","(","bool",")",":","If","true",",","the","regression","loss","would","be","applied","directly","on","decoded","bounding","boxes",",","converting","both","the","predicted","boxes","and","regression","targets","to","absolute","coordinates","format",".","Defaults","to","False",".","It","should","be","`","True","`","when","using","`","IoULoss","`",",","`","GIoULoss","`",",","or","`","DIoULoss","`","in","the","bbox","head",".","deform_groups",":","(","int",")",":","Group","number","of","DCN","in","FeatureAdaption","module",".","Defaults","to","4.","loc_filter_thr","(","float",")",":","Threshold","to","filter","out","unconcerned","regions",".","Defaults","to","0.01.","loss_loc","(",":","obj",":","`","ConfigDict","`","or","dict",")",":","Config","of","location","loss",".","loss_shape","(",":","obj",":","`","ConfigDict","`","or","dict",")",":","Config","of","anchor","shape","loss",".","loss_cls","(",":","obj",":","`","ConfigDict","`","or","dict",")",":","Config","of","classification","loss",".","loss_bbox","(",":","obj",":","`","ConfigDict","`","or","dict",")",":","Config","of","bbox","regression","loss",".","init_cfg","(",":","obj",":","`","ConfigDict","`","or","list","[",":","obj",":","`","ConfigDict","`","]","or","dict","or","list","[","dict","]",",","optional",")",":","Initialization","config","dict","."]
docstr: Transform a single image's features extracted from the head into
  bbox results.
  
  Args:
      cls_scores (list[Tensor]): Box scores from all scale
          levels of a single image, each item has shape
          (num_priors * num_classes, H, W).
      bbox_preds (list[Tensor]): Box energies / deltas from
          all scale levels of a single image, each item has shape
          (num_priors * 4, H, W).
      mlvl_anchors (list[Tensor]): Each element in the list is
          the anchors of a single level in feature pyramid. it has
          shape (num_priors, 4).
      mlvl_masks (list[Tensor]): Each element in the list is location
          masks of a single level.
      img_meta (dict): Image meta info.
      cfg (:obj:`ConfigDict` or dict): Test / postprocessing
          configuration, if None, test_cfg would be used.
      rescale (bool): If True, return boxes in original image space.
          Defaults to False.
  
  Returns:
      :obj:`InstanceData`: Detection results of each image
      after the post process.
      Each item usually contains following keys.
  
      - scores (Tensor): Classification scores, has a shape
        (num_instance, )
      - labels (Tensor): Labels of bboxes, has a shape (num_instances, ).
      - bboxes (Tensor): Has a shape (num_instances, 4), the last
        dimension 4 arrange as (x1, y1, x2, y2).
docstr_tok: ["Transform","a","single","image","'s","features","extracted","from","the","head","into","bbox","results",".","Args",":","cls_scores","(","list","[","Tensor","]",")",":","Box","scores","from","all","scale","levels","of","a","single","image",",","each","item","has","shape","(","num_priors","*","num_classes",",","H",",","W",")",".","bbox_preds","(","list","[","Tensor","]",")",":","Box","energies","\/","deltas","from","all","scale","levels","of","a","single","image",",","each","item","has","shape","(","num_priors","*","4",",","H",",","W",")",".","mlvl_anchors","(","list","[","Tensor","]",")",":","Each","element","in","the","list","is","the","anchors","of","a","single","level","in","feature","pyramid",".","it","has","shape","(","num_priors",",","4",")",".","mlvl_masks","(","list","[","Tensor","]",")",":","Each","element","in","the","list","is","location","masks","of","a","single","level",".","img_meta","(","dict",")",":","Image","meta","info",".","cfg","(",":","obj",":","`","ConfigDict","`","or","dict",")",":","Test","\/","postprocessing","configuration",",","if","None",",","test_cfg","would","be","used",".","rescale","(","bool",")",":","If","True",",","return","boxes","in","original","image","space",".","Defaults","to","False",".","Returns",":",":","obj",":","`","InstanceData","`",":","Detection","results","of","each","image","after","the","post","process",".","Each","item","usually","contains","following","keys",".","-","scores","(","Tensor",")",":","Classification","scores",",","has","a","shape","(","num_instance",",",")","-","labels","(","Tensor",")",":","Labels","of","bboxes",",","has","a","shape","(","num_instances",",",")",".","-","bboxes","(","Tensor",")",":","Has","a","shape","(","num_instances",",","4",")",",","the","last","dimension","4","arrange","as","(","x1",",","y1",",","x2",",","y2",")","."]
code: def _predict_by_feat_single(
      self,
      cls_scores: List[Tensor],
      bbox_preds: List[Tensor],
      mlvl_anchors: List[Tensor],
      mlvl_masks: List[Tensor],
      img_meta: dict,
      cfg: ConfigType,
      rescale: bool = False,
  ) -> InstanceData:
      """Transform a single image's features extracted from the head into
      bbox results.
  
      Args:
          cls_scores (list[Tensor]): Box scores from all scale
              levels of a single image, each item has shape
              (num_priors * num_classes, H, W).
          bbox_preds (list[Tensor]): Box energies / deltas from
              all scale levels of a single image, each item has shape
              (num_priors * 4, H, W).
          mlvl_anchors (list[Tensor]): Each element in the list is
              the anchors of a single level in feature pyramid. it has
              shape (num_priors, 4).
          mlvl_masks (list[Tensor]): Each element in the list is location
              masks of a single level.
          img_meta (dict): Image meta info.
          cfg (:obj:`ConfigDict` or dict): Test / postprocessing
              configuration, if None, test_cfg would be used.
          rescale (bool): If True, return boxes in original image space.
              Defaults to False.
  
      Returns:
          :obj:`InstanceData`: Detection results of each image
          after the post process.
          Each item usually contains following keys.
  
          - scores (Tensor): Classification scores, has a shape
            (num_instance, )
          - labels (Tensor): Labels of bboxes, has a shape (num_instances, ).
          - bboxes (Tensor): Has a shape (num_instances, 4), the last
            dimension 4 arrange as (x1, y1, x2, y2).
      """
      cfg = self.test_cfg if cfg is None else cfg
      assert len(cls_scores) == len(bbox_preds) == len(mlvl_anchors)
      mlvl_bbox_preds = []
      mlvl_valid_anchors = []
      mlvl_scores = []
      for cls_score, bbox_pred, anchors, mask in zip(
          cls_scores, bbox_preds, mlvl_anchors, mlvl_masks
      ):
          assert cls_score.size()[-2:] == bbox_pred.size()[-2:]
          # if no location is kept, end.
          if mask.sum() == 0:
              continue
          # reshape scores and bbox_pred
          cls_score = cls_score.permute(1, 2, 0).reshape(
              -1, self.cls_out_channels
          )
          if self.use_sigmoid_cls:
              scores = cls_score.sigmoid()
          else:
              scores = cls_score.softmax(-1)
          bbox_pred = bbox_pred.permute(1, 2, 0).reshape(-1, 4)
          # filter scores, bbox_pred w.r.t. mask.
          # anchors are filtered in get_anchors() beforehand.
          scores = scores[mask, :]
          bbox_pred = bbox_pred[mask, :]
          if scores.dim() == 0:
              anchors = anchors.unsqueeze(0)
              scores = scores.unsqueeze(0)
              bbox_pred = bbox_pred.unsqueeze(0)
          # filter anchors, bbox_pred, scores w.r.t. scores
          nms_pre = cfg.get("nms_pre", -1)
          if nms_pre > 0 and scores.shape[0] > nms_pre:
              if self.use_sigmoid_cls:
                  max_scores, _ = scores.max(dim=1)
              else:
                  # remind that we set FG labels to [0, num_class-1]
                  # since mmdet v2.0
                  # BG cat_id: num_class
                  max_scores, _ = scores[:, :-1].max(dim=1)
              _, topk_inds = max_scores.topk(nms_pre)
              anchors = anchors[topk_inds, :]
              bbox_pred = bbox_pred[topk_inds, :]
              scores = scores[topk_inds, :]
  
          mlvl_bbox_preds.append(bbox_pred)
          mlvl_valid_anchors.append(anchors)
          mlvl_scores.append(scores)
  
      mlvl_bbox_preds = torch.cat(mlvl_bbox_preds)
      mlvl_anchors = torch.cat(mlvl_valid_anchors)
      mlvl_scores = torch.cat(mlvl_scores)
      mlvl_bboxes = self.bbox_coder.decode(
          mlvl_anchors, mlvl_bbox_preds, max_shape=img_meta["img_shape"]
      )
  
      if rescale:
          assert img_meta.get("scale_factor") is not None
          mlvl_bboxes /= mlvl_bboxes.new_tensor(
              img_meta["scale_factor"]
          ).repeat((1, 2))
  
      if self.use_sigmoid_cls:
          # 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)
      # multi class NMS
      det_bboxes, det_labels = multiclass_nms(
          mlvl_bboxes,
          mlvl_scores,
          cfg.score_thr,
          cfg.nms,
          cfg.max_per_img,
      )
  
      results = InstanceData()
      results.bboxes = det_bboxes[:, :-1]
      results.scores = det_bboxes[:, -1]
      results.labels = det_labels
      return results
  
imports: from typing import List, Optional, Tuple
  import torch
  import torch.nn
  from mmcv.ops import DeformConv2d, MaskedConv2d
  from mmengine.model import BaseModule
  from mmengine.structures import InstanceData
  from torch import Tensor
  from mmdet.registry import MODELS, TASK_UTILS
  from mmdet.utils import ConfigType, InstanceList, MultiConfig, OptConfigType, OptInstanceList
  from ..layers import multiclass_nms
  from ..task_modules.prior_generators import anchor_inside_flags, calc_region
  from ..task_modules.samplers import PseudoSampler
  from ..utils import images_to_levels, multi_apply, unmap
  from .anchor_head import AnchorHead
label_desc: Use image node_id 15 for calling the GuidedAnchorHead obj's underlying member method code with example usage: obj._predict_by_feat_single(cls_scores, bbox_preds, mlvl_anchors, mlvl_masks, img_meta, cfg, rescale) and returns: results