class_docstr: Anchor-based head (RPN, RetinaNet, SSD, etc.).
  
  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. Used in child classes.
      anchor_generator (dict): Config dict for anchor generator
      bbox_coder (dict): Config of bounding box 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. Default False. It should be `True` when
          using `IoULoss`, `GIoULoss`, or `DIoULoss` in the bbox head.
      loss_cls (dict): Config of classification loss.
      loss_bbox (dict): Config of localization loss.
      train_cfg (dict): Training config of anchor head.
      test_cfg (dict): Testing config of anchor head.
      init_cfg (dict or list[dict], optional): Initialization config dict.
class_docstr_tok: ["Anchor-based","head","(","RPN",",","RetinaNet",",","SSD",",","etc.",")",".","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",".","Used","in","child","classes",".","anchor_generator","(","dict",")",":","Config","dict","for","anchor","generator","bbox_coder","(","dict",")",":","Config","of","bounding","box","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",".","Default","False",".","It","should","be","`","True","`","when","using","`","IoULoss","`",",","`","GIoULoss","`",",","or","`","DIoULoss","`","in","the","bbox","head",".","loss_cls","(","dict",")",":","Config","of","classification","loss",".","loss_bbox","(","dict",")",":","Config","of","localization","loss",".","train_cfg","(","dict",")",":","Training","config","of","anchor","head",".","test_cfg","(","dict",")",":","Testing","config","of","anchor","head",".","init_cfg","(","dict","or","list","[","dict","]",",","optional",")",":","Initialization","config","dict","."]
code: def __init__(
      self,
      num_classes: int,
      in_channels: int,
      feat_channels: int = 256,
      anchor_generator: ConfigType = dict(
          type="AnchorGenerator",
          scales=[8, 16, 32],
          ratios=[0.5, 1.0, 2.0],
          strides=[4, 8, 16, 32, 64],
      ),
      bbox_coder: ConfigType = dict(
          type="DeltaXYWHBBoxCoder",
          clip_border=True,
          target_means=(0.0, 0.0, 0.0, 0.0),
          target_stds=(1.0, 1.0, 1.0, 1.0),
      ),
      reg_decoded_bbox: bool = False,
      loss_cls: ConfigType = dict(
          type="CrossEntropyLoss", use_sigmoid=True, loss_weight=1.0
      ),
      loss_bbox: ConfigType = dict(
          type="SmoothL1Loss", beta=1.0 / 9.0, loss_weight=1.0
      ),
      train_cfg: OptConfigType = None,
      test_cfg: OptConfigType = None,
      init_cfg: OptMultiConfig = dict(
          type="Normal", layer="Conv2d", std=0.01
      ),
  ) -> None:
      super().__init__(init_cfg=init_cfg)
      self.in_channels = in_channels
      self.num_classes = num_classes
      self.feat_channels = feat_channels
      self.use_sigmoid_cls = loss_cls.get("use_sigmoid", False)
      if self.use_sigmoid_cls:
          self.cls_out_channels = num_classes
      else:
          self.cls_out_channels = num_classes + 1
  
      if self.cls_out_channels <= 0:
          raise ValueError(f"num_classes={num_classes} is too small")
      self.reg_decoded_bbox = reg_decoded_bbox
  
      self.bbox_coder = TASK_UTILS.build(bbox_coder)
      self.loss_cls = MODELS.build(loss_cls)
      self.loss_bbox = MODELS.build(loss_bbox)
      self.train_cfg = train_cfg
      self.test_cfg = test_cfg
      if self.train_cfg:
          self.assigner = TASK_UTILS.build(self.train_cfg["assigner"])
          if train_cfg.get("sampler", None) is not None:
              self.sampler = TASK_UTILS.build(
                  self.train_cfg["sampler"],
                  default_args=dict(context=self),
              )
          else:
              self.sampler = PseudoSampler(context=self)
  
      self.fp16_enabled = False
  
      self.prior_generator = TASK_UTILS.build(anchor_generator)
  
      # Usually the numbers of anchors for each level are the same
      # except SSD detectors. So it is an int in the most dense
      # heads but a list of int in SSDHead
      self.num_base_priors = self.prior_generator.num_base_priors[0]
      self._init_layers()
  
imports: import warnings
  from typing import List, Optional, Tuple, Union
  import torch
  import torch.nn
  from mmengine.structures import InstanceData
  from torch import Tensor
  from mmdet.registry import MODELS, TASK_UTILS
  from mmdet.structures.bbox import BaseBoxes, cat_boxes, get_box_tensor
  from mmdet.utils import ConfigType, InstanceList, OptConfigType, OptInstanceList, OptMultiConfig
  from ..task_modules.prior_generators import AnchorGenerator, anchor_inside_flags
  from ..task_modules.samplers import PseudoSampler
  from ..utils import images_to_levels, multi_apply, unmap
  from .base_dense_head import BaseDenseHead
label_desc: Use image node_id 1 to create a new AnchorHead object from inherited base classes: BaseDenseHead with example: obj = AnchorHead(num_classes, in_channels, feat_channels, anchor_generator, bbox_coder, reg_decoded_bbox, loss_cls, loss_bbox, train_cfg, test_cfg, init_cfg)