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.
      approx_anchor_generator (dict): Config dict for approx generator
      square_anchor_generator (dict): Config dict for square generator
      anchor_coder (dict): Config dict for anchor coder
      bbox_coder (dict): Config dict for bbox coder
      deform_groups: (int): Group number of DCN in
          FeatureAdaption module.
      loc_filter_thr (float): Threshold to filter out unconcerned regions.
      loss_loc (dict): Config of location loss.
      loss_shape (dict): Config of anchor shape loss.
      loss_cls (dict): Config of classification loss.
      loss_bbox (dict): Config of bbox regression loss.
code: def __init__(
      self,
      num_classes,
      in_channels,
      feat_channels=256,
      approx_anchor_generator=dict(
          type="AnchorGenerator",
          octave_base_scale=8,
          scales_per_octave=3,
          ratios=[0.5, 1.0, 2.0],
          strides=[4, 8, 16, 32, 64],
      ),
      square_anchor_generator=dict(
          type="AnchorGenerator",
          ratios=[1.0],
          scales=[8],
          strides=[4, 8, 16, 32, 64],
      ),
      anchor_coder=dict(
          type="DeltaXYWHBBoxCoder",
          target_means=[0.0, 0.0, 0.0, 0.0],
          target_stds=[1.0, 1.0, 1.0, 1.0],
      ),
      bbox_coder=dict(
          type="DeltaXYWHBBoxCoder",
          target_means=[0.0, 0.0, 0.0, 0.0],
          target_stds=[1.0, 1.0, 1.0, 1.0],
      ),
      reg_decoded_bbox=False,
      deform_groups=4,
      loc_filter_thr=0.01,
      train_cfg=None,
      test_cfg=None,
      loss_loc=dict(
          type="FocalLoss",
          use_sigmoid=True,
          gamma=2.0,
          alpha=0.25,
          loss_weight=1.0,
      ),
      loss_shape=dict(type="BoundedIoULoss", beta=0.2, loss_weight=1.0),
      loss_cls=dict(
          type="CrossEntropyLoss", use_sigmoid=True, loss_weight=1.0
      ),
      loss_bbox=dict(type="SmoothL1Loss", beta=1.0, loss_weight=1.0),
  ):  # yapf: disable
      super(AnchorHead, self).__init__()
      self.in_channels = in_channels
      self.num_classes = num_classes
      self.feat_channels = feat_channels
      self.deform_groups = deform_groups
      self.loc_filter_thr = loc_filter_thr
  
      # build approx_anchor_generator and square_anchor_generator
      assert (
          approx_anchor_generator["octave_base_scale"]
          == square_anchor_generator["scales"][0]
      )
      assert (
          approx_anchor_generator["strides"]
          == square_anchor_generator["strides"]
      )
      self.approx_anchor_generator = build_anchor_generator(
          approx_anchor_generator
      )
      self.square_anchor_generator = build_anchor_generator(
          square_anchor_generator
      )
      self.approxs_per_octave = (
          self.approx_anchor_generator.num_base_anchors[0]
      )
  
      self.reg_decoded_bbox = reg_decoded_bbox
  
      # one anchor per location
      self.num_anchors = 1
      self.use_sigmoid_cls = loss_cls.get("use_sigmoid", False)
      self.loc_focal_loss = loss_loc["type"] in ["FocalLoss"]
      self.sampling = loss_cls["type"] not in ["FocalLoss"]
      self.ga_sampling = train_cfg is not None and hasattr(
          train_cfg, "ga_sampler"
      )
      if self.use_sigmoid_cls:
          self.cls_out_channels = self.num_classes
      else:
          self.cls_out_channels = self.num_classes + 1
  
      # build bbox_coder
      self.anchor_coder = build_bbox_coder(anchor_coder)
      self.bbox_coder = build_bbox_coder(bbox_coder)
  
      # build losses
      self.loss_loc = build_loss(loss_loc)
      self.loss_shape = build_loss(loss_shape)
      self.loss_cls = build_loss(loss_cls)
      self.loss_bbox = build_loss(loss_bbox)
  
      self.train_cfg = train_cfg
      self.test_cfg = test_cfg
  
      if self.train_cfg:
          self.assigner = build_assigner(self.train_cfg.assigner)
          # use PseudoSampler when sampling is False
          if self.sampling and hasattr(self.train_cfg, "sampler"):
              sampler_cfg = self.train_cfg.sampler
          else:
              sampler_cfg = dict(type="PseudoSampler")
          self.sampler = build_sampler(sampler_cfg, context=self)
  
          self.ga_assigner = build_assigner(self.train_cfg.ga_assigner)
          if self.ga_sampling:
              ga_sampler_cfg = self.train_cfg.ga_sampler
          else:
              ga_sampler_cfg = dict(type="PseudoSampler")
          self.ga_sampler = build_sampler(ga_sampler_cfg, context=self)
  
      self.fp16_enabled = False
  
      self._init_layers()
  
imports: import torch
  import torch.nn
  from mmcv.cnn import bias_init_with_prob, normal_init
  from mmcv.ops import DeformConv2d, MaskedConv2d
  from mmcv.runner import force_fp32
  from mmdet.core import anchor_inside_flags, build_anchor_generator, build_assigner, build_bbox_coder, build_sampler, calc_region, images_to_levels, multi_apply, multiclass_nms, unmap
  from ..builder import HEADS, build_loss
  from .anchor_head import AnchorHead
label_desc: Use image node_id 1 to create a new GuidedAnchorHead object from inherited base classes: AnchorHead with example: obj = GuidedAnchorHead(num_classes, in_channels, feat_channels, approx_anchor_generator, square_anchor_generator, anchor_coder, bbox_coder, reg_decoded_bbox, deform_groups, loc_filter_thr, train_cfg, test_cfg, loss_loc, loss_shape, loss_cls, loss_bbox)