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 loss(
      self,
      cls_scores,
      bbox_preds,
      shape_preds,
      loc_preds,
      gt_bboxes,
      gt_labels,
      img_metas,
      gt_bboxes_ignore=None,
  ):
      featmap_sizes = [featmap.size()[-2:] for featmap in cls_scores]
      assert (
          len(featmap_sizes) == self.approx_anchor_generator.num_levels
      )
  
      device = cls_scores[0].device
  
      # get loc targets
      loc_targets, loc_weights, loc_avg_factor = self.ga_loc_targets(
          gt_bboxes, featmap_sizes
      )
  
      # get sampled approxes
      approxs_list, inside_flag_list = self.get_sampled_approxs(
          featmap_sizes, img_metas, device=device
      )
      # get squares and guided anchors
      squares_list, guided_anchors_list, _ = self.get_anchors(
          featmap_sizes,
          shape_preds,
          loc_preds,
          img_metas,
          device=device,
      )
  
      # get shape targets
      shape_targets = self.ga_shape_targets(
          approxs_list,
          inside_flag_list,
          squares_list,
          gt_bboxes,
          img_metas,
      )
      if shape_targets is None:
          return None
      (
          bbox_anchors_list,
          bbox_gts_list,
          anchor_weights_list,
          anchor_fg_num,
          anchor_bg_num,
      ) = shape_targets
      anchor_total_num = (
          anchor_fg_num
          if not self.ga_sampling
          else anchor_fg_num + anchor_bg_num
      )
  
      # get anchor targets
      label_channels = (
          self.cls_out_channels if self.use_sigmoid_cls else 1
      )
      cls_reg_targets = self.get_targets(
          guided_anchors_list,
          inside_flag_list,
          gt_bboxes,
          img_metas,
          gt_bboxes_ignore_list=gt_bboxes_ignore,
          gt_labels_list=gt_labels,
          label_channels=label_channels,
      )
      if cls_reg_targets is None:
          return None
      (
          labels_list,
          label_weights_list,
          bbox_targets_list,
          bbox_weights_list,
          num_total_pos,
          num_total_neg,
      ) = cls_reg_targets
      num_total_samples = (
          num_total_pos + num_total_neg
          if self.sampling
          else num_total_pos
      )
  
      # anchor number of multi levels
      num_level_anchors = [
          anchors.size(0) for anchors in guided_anchors_list[0]
      ]
      # concat all level anchors to a single tensor
      concat_anchor_list = []
      for i in range(len(guided_anchors_list)):
          concat_anchor_list.append(torch.cat(guided_anchors_list[i]))
      all_anchor_list = images_to_levels(
          concat_anchor_list, num_level_anchors
      )
  
      # get classification and bbox regression losses
      losses_cls, losses_bbox = multi_apply(
          self.loss_single,
          cls_scores,
          bbox_preds,
          all_anchor_list,
          labels_list,
          label_weights_list,
          bbox_targets_list,
          bbox_weights_list,
          num_total_samples=num_total_samples,
      )
  
      # get anchor location loss
      losses_loc = []
      for i in range(len(loc_preds)):
          loss_loc = self.loss_loc_single(
              loc_preds[i],
              loc_targets[i],
              loc_weights[i],
              loc_avg_factor=loc_avg_factor,
          )
          losses_loc.append(loss_loc)
  
      # get anchor shape loss
      losses_shape = []
      for i in range(len(shape_preds)):
          loss_shape = self.loss_shape_single(
              shape_preds[i],
              bbox_anchors_list[i],
              bbox_gts_list[i],
              anchor_weights_list[i],
              anchor_total_num=anchor_total_num,
          )
          losses_shape.append(loss_shape)
  
      return dict(
          loss_cls=losses_cls,
          loss_bbox=losses_bbox,
          loss_shape=losses_shape,
          loss_loc=losses_loc,
      )
  
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 14 for calling the GuidedAnchorHead obj's underlying member method code with example usage: obj.loss(cls_scores, bbox_preds, shape_preds, loc_preds, gt_bboxes, gt_labels, img_metas, gt_bboxes_ignore) and returns: dict, None, None