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.
docstr: Compute location targets for guided anchoring.
  
  Each feature map is divided into positive, negative and ignore regions.
  - positive regions: target 1, weight 1
  - ignore regions: target 0, weight 0
  - negative regions: target 0, weight 0.1
  
  Args:
      gt_bboxes_list (list[Tensor]): Gt bboxes of each image.
      featmap_sizes (list[tuple]): Multi level sizes of each feature
          maps.
  
  Returns:
      tuple
docstr_tok: ["Compute","location","targets","for","guided","anchoring",".","Each","feature","map","is","divided","into","positive",",","negative","and","ignore","regions",".","-","positive","regions",":","target","1",",","weight","1","-","ignore","regions",":","target","0",",","weight","0","-","negative","regions",":","target","0",",","weight","0.1","Args",":","gt_bboxes_list","(","list","[","Tensor","]",")",":","Gt","bboxes","of","each","image",".","featmap_sizes","(","list","[","tuple","]",")",":","Multi","level","sizes","of","each","feature","maps",".","Returns",":","tuple"]
code: def ga_loc_targets(self, gt_bboxes_list, featmap_sizes):
      """Compute location targets for guided anchoring.
  
      Each feature map is divided into positive, negative and ignore regions.
      - positive regions: target 1, weight 1
      - ignore regions: target 0, weight 0
      - negative regions: target 0, weight 0.1
  
      Args:
          gt_bboxes_list (list[Tensor]): Gt bboxes of each image.
          featmap_sizes (list[tuple]): Multi level sizes of each feature
              maps.
  
      Returns:
          tuple
      """
      anchor_scale = self.approx_anchor_generator.octave_base_scale
      anchor_strides = self.approx_anchor_generator.strides
      # Currently only supports same stride in x and y direction.
      for stride in anchor_strides:
          assert stride[0] == stride[1]
      anchor_strides = [stride[0] for stride in anchor_strides]
  
      center_ratio = self.train_cfg.center_ratio
      ignore_ratio = self.train_cfg.ignore_ratio
      img_per_gpu = len(gt_bboxes_list)
      num_lvls = len(featmap_sizes)
      r1 = (1 - center_ratio) / 2
      r2 = (1 - ignore_ratio) / 2
      all_loc_targets = []
      all_loc_weights = []
      all_ignore_map = []
      for lvl_id in range(num_lvls):
          h, w = featmap_sizes[lvl_id]
          loc_targets = torch.zeros(
              img_per_gpu,
              1,
              h,
              w,
              device=gt_bboxes_list[0].device,
              dtype=torch.float32,
          )
          loc_weights = torch.full_like(loc_targets, -1)
          ignore_map = torch.zeros_like(loc_targets)
          all_loc_targets.append(loc_targets)
          all_loc_weights.append(loc_weights)
          all_ignore_map.append(ignore_map)
      for img_id in range(img_per_gpu):
          gt_bboxes = gt_bboxes_list[img_id]
          scale = torch.sqrt(
              (gt_bboxes[:, 2] - gt_bboxes[:, 0])
              * (gt_bboxes[:, 3] - gt_bboxes[:, 1])
          )
          min_anchor_size = scale.new_full(
              (1,), float(anchor_scale * anchor_strides[0])
          )
          # assign gt bboxes to different feature levels w.r.t. their scales
          target_lvls = torch.floor(
              torch.log2(scale) - torch.log2(min_anchor_size) + 0.5
          )
          target_lvls = target_lvls.clamp(
              min=0, max=num_lvls - 1
          ).long()
          for gt_id in range(gt_bboxes.size(0)):
              lvl = target_lvls[gt_id].item()
              # rescaled to corresponding feature map
              gt_ = gt_bboxes[gt_id, :4] / anchor_strides[lvl]
              # calculate ignore regions
              ignore_x1, ignore_y1, ignore_x2, ignore_y2 = calc_region(
                  gt_, r2, featmap_sizes[lvl]
              )
              # calculate positive (center) regions
              ctr_x1, ctr_y1, ctr_x2, ctr_y2 = calc_region(
                  gt_, r1, featmap_sizes[lvl]
              )
              all_loc_targets[lvl][
                  img_id, 0, ctr_y1 : ctr_y2 + 1, ctr_x1 : ctr_x2 + 1
              ] = 1
              all_loc_weights[lvl][
                  img_id,
                  0,
                  ignore_y1 : ignore_y2 + 1,
                  ignore_x1 : ignore_x2 + 1,
              ] = 0
              all_loc_weights[lvl][
                  img_id, 0, ctr_y1 : ctr_y2 + 1, ctr_x1 : ctr_x2 + 1
              ] = 1
              # calculate ignore map on nearby low level feature
              if lvl > 0:
                  d_lvl = lvl - 1
                  # rescaled to corresponding feature map
                  gt_ = gt_bboxes[gt_id, :4] / anchor_strides[d_lvl]
                  (
                      ignore_x1,
                      ignore_y1,
                      ignore_x2,
                      ignore_y2,
                  ) = calc_region(gt_, r2, featmap_sizes[d_lvl])
                  all_ignore_map[d_lvl][
                      img_id,
                      0,
                      ignore_y1 : ignore_y2 + 1,
                      ignore_x1 : ignore_x2 + 1,
                  ] = 1
              # calculate ignore map on nearby high level feature
              if lvl < num_lvls - 1:
                  u_lvl = lvl + 1
                  # rescaled to corresponding feature map
                  gt_ = gt_bboxes[gt_id, :4] / anchor_strides[u_lvl]
                  (
                      ignore_x1,
                      ignore_y1,
                      ignore_x2,
                      ignore_y2,
                  ) = calc_region(gt_, r2, featmap_sizes[u_lvl])
                  all_ignore_map[u_lvl][
                      img_id,
                      0,
                      ignore_y1 : ignore_y2 + 1,
                      ignore_x1 : ignore_x2 + 1,
                  ] = 1
      for lvl_id in range(num_lvls):
          # ignore negative regions w.r.t. ignore map
          all_loc_weights[lvl_id][
              (all_loc_weights[lvl_id] < 0)
              & (all_ignore_map[lvl_id] > 0)
          ] = 0
          # set negative regions with weight 0.1
          all_loc_weights[lvl_id][all_loc_weights[lvl_id] < 0] = 0.1
      # loc average factor to balance loss
      loc_avg_factor = (
          sum(
              [
                  t.size(0) * t.size(-1) * t.size(-2)
                  for t in all_loc_targets
              ]
          )
          / 200
      )
      return all_loc_targets, all_loc_weights, loc_avg_factor
  
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 9 for calling the GuidedAnchorHead obj's underlying member method code with example usage: obj.ga_loc_targets(gt_bboxes_list, featmap_sizes) and returns: all_loc_targets,  all_loc_weights,  loc_avg_factor