class_docstr: YOLOXHead head used in `YOLOX <https://arxiv.org/abs/2107.08430>`_.
  
  Args:
      num_classes (int): Number of categories excluding the background
          category.
      in_channels (int): Number of channels in the input feature map.
      feat_channels (int): Number of hidden channels in stacking convs.
          Defaults to 256
      stacked_convs (int): Number of stacking convs of the head.
          Defaults to (8, 16, 32).
      strides (Sequence[int]): Downsample factor of each feature map.
           Defaults to None.
      use_depthwise (bool): Whether to depthwise separable convolution in
          blocks. Defaults to False.
      dcn_on_last_conv (bool): If true, use dcn in the last layer of
          towers. Defaults to False.
      conv_bias (bool or 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. Defaults to "auto".
      conv_cfg (:obj:`ConfigDict` or dict, optional): Config dict for
          convolution layer. Defaults to None.
      norm_cfg (:obj:`ConfigDict` or dict): Config dict for normalization
          layer. Defaults to dict(type='BN', momentum=0.03, eps=0.001).
      act_cfg (:obj:`ConfigDict` or dict): Config dict for activation layer.
          Defaults to None.
      loss_cls (:obj:`ConfigDict` or dict): Config of classification loss.
      loss_bbox (:obj:`ConfigDict` or dict): Config of localization loss.
      loss_obj (:obj:`ConfigDict` or dict): Config of objectness loss.
      loss_l1 (:obj:`ConfigDict` or dict): Config of L1 loss.
      train_cfg (:obj:`ConfigDict` or dict, optional): Training config of
          anchor head. Defaults to None.
      test_cfg (:obj:`ConfigDict` or dict, optional): Testing config of
          anchor head. Defaults to None.
      init_cfg (:obj:`ConfigDict` or list[:obj:`ConfigDict`] or dict or
          list[dict], optional): Initialization config dict.
          Defaults to None.
class_docstr_tok: ["YOLOXHead","head","used","in","`","YOLOX","<","https",":","\/\/arxiv.org\/abs\/2107.08430",">","`","_",".","Args",":","num_classes","(","int",")",":","Number","of","categories","excluding","the","background","category",".","in_channels","(","int",")",":","Number","of","channels","in","the","input","feature","map",".","feat_channels","(","int",")",":","Number","of","hidden","channels","in","stacking","convs",".","Defaults","to","256","stacked_convs","(","int",")",":","Number","of","stacking","convs","of","the","head",".","Defaults","to","(","8",",","16",",","32",")",".","strides","(","Sequence","[","int","]",")",":","Downsample","factor","of","each","feature","map",".","Defaults","to","None",".","use_depthwise","(","bool",")",":","Whether","to","depthwise","separable","convolution","in","blocks",".","Defaults","to","False",".","dcn_on_last_conv","(","bool",")",":","If","true",",","use","dcn","in","the","last","layer","of","towers",".","Defaults","to","False",".","conv_bias","(","bool","or","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",".","Defaults","to","``","auto","''",".","conv_cfg","(",":","obj",":","`","ConfigDict","`","or","dict",",","optional",")",":","Config","dict","for","convolution","layer",".","Defaults","to","None",".","norm_cfg","(",":","obj",":","`","ConfigDict","`","or","dict",")",":","Config","dict","for","normalization","layer",".","Defaults","to","dict","(","type='BN","'",",","momentum=0.03",",","eps=0.001",")",".","act_cfg","(",":","obj",":","`","ConfigDict","`","or","dict",")",":","Config","dict","for","activation","layer",".","Defaults","to","None",".","loss_cls","(",":","obj",":","`","ConfigDict","`","or","dict",")",":","Config","of","classification","loss",".","loss_bbox","(",":","obj",":","`","ConfigDict","`","or","dict",")",":","Config","of","localization","loss",".","loss_obj","(",":","obj",":","`","ConfigDict","`","or","dict",")",":","Config","of","objectness","loss",".","loss_l1","(",":","obj",":","`","ConfigDict","`","or","dict",")",":","Config","of","L1","loss",".","train_cfg","(",":","obj",":","`","ConfigDict","`","or","dict",",","optional",")",":","Training","config","of","anchor","head",".","Defaults","to","None",".","test_cfg","(",":","obj",":","`","ConfigDict","`","or","dict",",","optional",")",":","Testing","config","of","anchor","head",".","Defaults","to","None",".","init_cfg","(",":","obj",":","`","ConfigDict","`","or","list","[",":","obj",":","`","ConfigDict","`","]","or","dict","or","list","[","dict","]",",","optional",")",":","Initialization","config","dict",".","Defaults","to","None","."]
docstr: Transform a batch of output features extracted by the head into
  bbox results.
  Args:
      cls_scores (list[Tensor]): Classification scores for all
          scale levels, each is a 4D-tensor, has shape
          (batch_size, num_priors * num_classes, H, W).
      bbox_preds (list[Tensor]): Box energies / deltas for all
          scale levels, each is a 4D-tensor, has shape
          (batch_size, num_priors * 4, H, W).
      objectnesses (list[Tensor], Optional): Score factor for
          all scale level, each is a 4D-tensor, has shape
          (batch_size, 1, H, W).
      batch_img_metas (list[dict], Optional): Batch image meta info.
          Defaults to None.
      cfg (ConfigDict, optional): Test / postprocessing
          configuration, if None, test_cfg would be used.
          Defaults to None.
      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:
      list[:obj:`InstanceData`]: Object 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","batch","of","output","features","extracted","by","the","head","into","bbox","results",".","Args",":","cls_scores","(","list","[","Tensor","]",")",":","Classification","scores","for","all","scale","levels",",","each","is","a","4D-tensor",",","has","shape","(","batch_size",",","num_priors","*","num_classes",",","H",",","W",")",".","bbox_preds","(","list","[","Tensor","]",")",":","Box","energies","\/","deltas","for","all","scale","levels",",","each","is","a","4D-tensor",",","has","shape","(","batch_size",",","num_priors","*","4",",","H",",","W",")",".","objectnesses","(","list","[","Tensor","]",",","Optional",")",":","Score","factor","for","all","scale","level",",","each","is","a","4D-tensor",",","has","shape","(","batch_size",",","1",",","H",",","W",")",".","batch_img_metas","(","list","[","dict","]",",","Optional",")",":","Batch","image","meta","info",".","Defaults","to","None",".","cfg","(","ConfigDict",",","optional",")",":","Test","\/","postprocessing","configuration",",","if","None",",","test_cfg","would","be","used",".","Defaults","to","None",".","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",":","list","[",":","obj",":","`","InstanceData","`","]",":","Object","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(
      self,
      cls_scores: List[Tensor],
      bbox_preds: List[Tensor],
      objectnesses: Optional[List[Tensor]],
      batch_img_metas: Optional[List[dict]] = None,
      cfg: Optional[ConfigDict] = None,
      rescale: bool = False,
      with_nms: bool = True,
  ) -> List[InstanceData]:
      """Transform a batch of output features extracted by the head into
      bbox results.
      Args:
          cls_scores (list[Tensor]): Classification scores for all
              scale levels, each is a 4D-tensor, has shape
              (batch_size, num_priors * num_classes, H, W).
          bbox_preds (list[Tensor]): Box energies / deltas for all
              scale levels, each is a 4D-tensor, has shape
              (batch_size, num_priors * 4, H, W).
          objectnesses (list[Tensor], Optional): Score factor for
              all scale level, each is a 4D-tensor, has shape
              (batch_size, 1, H, W).
          batch_img_metas (list[dict], Optional): Batch image meta info.
              Defaults to None.
          cfg (ConfigDict, optional): Test / postprocessing
              configuration, if None, test_cfg would be used.
              Defaults to None.
          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:
          list[:obj:`InstanceData`]: Object 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).
      """
      assert len(cls_scores) == len(bbox_preds) == len(objectnesses)
      cfg = self.test_cfg if cfg is None else cfg
  
      num_imgs = len(batch_img_metas)
      featmap_sizes = [cls_score.shape[2:] for cls_score in cls_scores]
      mlvl_priors = self.prior_generator.grid_priors(
          featmap_sizes,
          dtype=cls_scores[0].dtype,
          device=cls_scores[0].device,
          with_stride=True,
      )
  
      # flatten cls_scores, bbox_preds and objectness
      flatten_cls_scores = [
          cls_score.permute(0, 2, 3, 1).reshape(
              num_imgs, -1, self.cls_out_channels
          )
          for cls_score in cls_scores
      ]
      flatten_bbox_preds = [
          bbox_pred.permute(0, 2, 3, 1).reshape(num_imgs, -1, 4)
          for bbox_pred in bbox_preds
      ]
      flatten_objectness = [
          objectness.permute(0, 2, 3, 1).reshape(num_imgs, -1)
          for objectness in objectnesses
      ]
  
      flatten_cls_scores = torch.cat(
          flatten_cls_scores, dim=1
      ).sigmoid()
      flatten_bbox_preds = torch.cat(flatten_bbox_preds, dim=1)
      flatten_objectness = torch.cat(
          flatten_objectness, dim=1
      ).sigmoid()
      flatten_priors = torch.cat(mlvl_priors)
  
      flatten_bboxes = self._bbox_decode(
          flatten_priors, flatten_bbox_preds
      )
  
      result_list = []
      for img_id, img_meta in enumerate(batch_img_metas):
          max_scores, labels = torch.max(flatten_cls_scores[img_id], 1)
          valid_mask = (
              flatten_objectness[img_id] * max_scores >= cfg.score_thr
          )
          results = InstanceData(
              bboxes=flatten_bboxes[img_id][valid_mask],
              scores=max_scores[valid_mask]
              * flatten_objectness[img_id][valid_mask],
              labels=labels[valid_mask],
          )
  
          result_list.append(
              self._bbox_post_process(
                  results=results,
                  cfg=cfg,
                  rescale=rescale,
                  with_nms=with_nms,
                  img_meta=img_meta,
              )
          )
  
      return result_list
  
imports: import math
  from typing import List, Optional, Sequence, Tuple, Union
  import torch
  import torch.nn
  import torch.nn.functional
  from mmcv.cnn import ConvModule, DepthwiseSeparableConvModule
  from mmcv.ops.nms import batched_nms
  from mmengine.config import ConfigDict
  from mmengine.model import bias_init_with_prob
  from mmengine.structures import InstanceData
  from torch import Tensor
  from mmdet.registry import MODELS, TASK_UTILS
  from mmdet.structures.bbox import bbox_xyxy_to_cxcywh
  from mmdet.utils import ConfigType, OptConfigType, OptInstanceList, OptMultiConfig, reduce_mean
  from ..task_modules.prior_generators import MlvlPointGenerator
  from ..task_modules.samplers import PseudoSampler
  from ..utils import multi_apply
  from .base_dense_head import BaseDenseHead
label_desc: Use image node_id 8 for calling the YOLOXHead obj's underlying member method code with example usage: obj.predict_by_feat(cls_scores, bbox_preds, objectnesses, batch_img_metas, cfg, rescale, with_nms) and returns: result_list