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","."]
code: def __init__(
      self,
      num_classes: int,
      in_channels: int,
      feat_channels: int = 256,
      stacked_convs: int = 2,
      strides: Sequence[int] = (8, 16, 32),
      use_depthwise: bool = False,
      dcn_on_last_conv: bool = False,
      conv_bias: Union[bool, str] = "auto",
      conv_cfg: OptConfigType = None,
      norm_cfg: ConfigType = dict(type="BN", momentum=0.03, eps=0.001),
      act_cfg: ConfigType = dict(type="Swish"),
      loss_cls: ConfigType = dict(
          type="CrossEntropyLoss",
          use_sigmoid=True,
          reduction="sum",
          loss_weight=1.0,
      ),
      loss_bbox: ConfigType = dict(
          type="IoULoss",
          mode="square",
          eps=1e-16,
          reduction="sum",
          loss_weight=5.0,
      ),
      loss_obj: ConfigType = dict(
          type="CrossEntropyLoss",
          use_sigmoid=True,
          reduction="sum",
          loss_weight=1.0,
      ),
      loss_l1: ConfigType = dict(
          type="L1Loss", reduction="sum", loss_weight=1.0
      ),
      train_cfg: OptConfigType = None,
      test_cfg: OptConfigType = None,
      init_cfg: OptMultiConfig = dict(
          type="Kaiming",
          layer="Conv2d",
          a=math.sqrt(5),
          distribution="uniform",
          mode="fan_in",
          nonlinearity="leaky_relu",
      ),
  ) -> None:
      super().__init__(init_cfg=init_cfg)
      self.num_classes = num_classes
      self.cls_out_channels = num_classes
      self.in_channels = in_channels
      self.feat_channels = feat_channels
      self.stacked_convs = stacked_convs
      self.strides = strides
      self.use_depthwise = use_depthwise
      self.dcn_on_last_conv = dcn_on_last_conv
      assert conv_bias == "auto" or isinstance(conv_bias, bool)
      self.conv_bias = conv_bias
      self.use_sigmoid_cls = True
  
      self.conv_cfg = conv_cfg
      self.norm_cfg = norm_cfg
      self.act_cfg = act_cfg
  
      self.loss_cls: nn.Module = MODELS.build(loss_cls)
      self.loss_bbox: nn.Module = MODELS.build(loss_bbox)
      self.loss_obj: nn.Module = MODELS.build(loss_obj)
  
      self.use_l1 = False  # This flag will be modified by hooks.
      self.loss_l1: nn.Module = MODELS.build(loss_l1)
  
      self.prior_generator = MlvlPointGenerator(strides, offset=0)
  
      self.test_cfg = test_cfg
      self.train_cfg = train_cfg
  
      if self.train_cfg:
          self.assigner = TASK_UTILS.build(self.train_cfg["assigner"])
          # YOLOX does not support sampling
          self.sampler = PseudoSampler()
  
      self._init_layers()
  
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 1 to create a new YOLOXHead object from inherited base classes: BaseDenseHead with example: obj = YOLOXHead(num_classes, in_channels, feat_channels, stacked_convs, strides, use_depthwise, dcn_on_last_conv, conv_bias, conv_cfg, norm_cfg, act_cfg, loss_cls, loss_bbox, loss_obj, loss_l1, train_cfg, test_cfg, init_cfg)