class_docstr: Generalized Focal Loss: Learning Qualified and Distributed Bounding
  Boxes for Dense Object Detection.
  
  GFL head structure is similar with ATSS, however GFL uses
  1) joint representation for classification and localization quality, and
  2) flexible General distribution for bounding box locations,
  which are supervised by
  Quality Focal Loss (QFL) and Distribution Focal Loss (DFL), respectively
  
  https://arxiv.org/abs/2006.04388
  
  Args:
      num_classes (int): Number of categories excluding the background
          category.
      in_channels (int): Number of channels in the input feature map.
      stacked_convs (int): Number of conv layers in cls and reg tower.
          Default: 4.
      conv_cfg (dict): dictionary to construct and config conv layer.
          Default: None.
      norm_cfg (dict): dictionary to construct and config norm layer.
          Default: dict(type='GN', num_groups=32, requires_grad=True).
      loss_qfl (dict): Config of Quality Focal Loss (QFL).
      reg_max (int): Max value of integral set :math: `{0, ..., reg_max}`
          in QFL setting. Default: 16.
  Example:
      >>> self = GFLHead(11, 7)
      >>> feats = [torch.rand(1, 7, s, s) for s in [4, 8, 16, 32, 64]]
      >>> cls_quality_score, bbox_pred = self.forward(feats)
      >>> assert len(cls_quality_score) == len(self.scales)
class_docstr_tok: ["Generalized","Focal","Loss",":","Learning","Qualified","and","Distributed","Bounding","Boxes","for","Dense","Object","Detection",".","GFL","head","structure","is","similar","with","ATSS",",","however","GFL","uses","1",")","joint","representation","for","classification","and","localization","quality",",","and","2",")","flexible","General","distribution","for","bounding","box","locations",",","which","are","supervised","by","Quality","Focal","Loss","(","QFL",")","and","Distribution","Focal","Loss","(","DFL",")",",","respectively","https",":","\/\/arxiv.org\/abs\/2006.04388","Args",":","num_classes","(","int",")",":","Number","of","categories","excluding","the","background","category",".","in_channels","(","int",")",":","Number","of","channels","in","the","input","feature","map",".","stacked_convs","(","int",")",":","Number","of","conv","layers","in","cls","and","reg","tower",".","Default",":","4.","conv_cfg","(","dict",")",":","dictionary","to","construct","and","config","conv","layer",".","Default",":","None",".","norm_cfg","(","dict",")",":","dictionary","to","construct","and","config","norm","layer",".","Default",":","dict","(","type='GN","'",",","num_groups=32",",","requires_grad=True",")",".","loss_qfl","(","dict",")",":","Config","of","Quality","Focal","Loss","(","QFL",")",".","reg_max","(","int",")",":","Max","value","of","integral","set",":","math",":","`","{","0",",","...",",","reg_max","}","`","in","QFL","setting",".","Default",":","16",".","Example",":",">",">",">","self","=","GFLHead","(","11",",","7",")",">",">",">","feats","=","[","torch.rand","(","1",",","7",",","s",",","s",")","for","s","in","[","4",",","8",",","16",",","32",",","64","]","]",">",">",">","cls_quality_score",",","bbox_pred","=","self.forward","(","feats",")",">",">",">","assert","len","(","cls_quality_score",")","==","len","(","self.scales",")"]
docstr: Get targets for GFL head.
  
  This method is almost the same as `AnchorHead.get_targets()`. Besides
  returning the targets as the parent method does, it also returns the
  anchors as the first element of the returned tuple.
docstr_tok: ["Get","targets","for","GFL","head",".","This","method","is","almost","the","same","as","`","AnchorHead.get_targets","(",")","`",".","Besides","returning","the","targets","as","the","parent","method","does",",","it","also","returns","the","anchors","as","the","first","element","of","the","returned","tuple","."]
code: def get_targets(
      self,
      anchor_list,
      valid_flag_list,
      gt_bboxes_list,
      img_metas,
      gt_bboxes_ignore_list=None,
      gt_labels_list=None,
      label_channels=1,
      unmap_outputs=True,
  ):
      """Get targets for GFL head.
  
      This method is almost the same as `AnchorHead.get_targets()`. Besides
      returning the targets as the parent method does, it also returns the
      anchors as the first element of the returned tuple.
      """
      num_imgs = len(img_metas)
      assert len(anchor_list) == len(valid_flag_list) == num_imgs
  
      # anchor number of multi levels
      num_level_anchors = [
          anchors.size(0) for anchors in anchor_list[0]
      ]
      num_level_anchors_list = [num_level_anchors] * num_imgs
  
      # concat all level anchors and flags to a single tensor
      for i in range(num_imgs):
          assert len(anchor_list[i]) == len(valid_flag_list[i])
          anchor_list[i] = torch.cat(anchor_list[i])
          valid_flag_list[i] = torch.cat(valid_flag_list[i])
  
      # compute targets for each image
      if gt_bboxes_ignore_list is None:
          gt_bboxes_ignore_list = [None for _ in range(num_imgs)]
      if gt_labels_list is None:
          gt_labels_list = [None for _ in range(num_imgs)]
      (
          all_anchors,
          all_labels,
          all_label_weights,
          all_bbox_targets,
          all_bbox_weights,
          pos_inds_list,
          neg_inds_list,
      ) = multi_apply(
          self._get_target_single,
          anchor_list,
          valid_flag_list,
          num_level_anchors_list,
          gt_bboxes_list,
          gt_bboxes_ignore_list,
          gt_labels_list,
          img_metas,
          label_channels=label_channels,
          unmap_outputs=unmap_outputs,
      )
      # no valid anchors
      if any([labels is None for labels in all_labels]):
          return None
      # sampled anchors of all images
      num_total_pos = sum(
          [max(inds.numel(), 1) for inds in pos_inds_list]
      )
      num_total_neg = sum(
          [max(inds.numel(), 1) for inds in neg_inds_list]
      )
      # split targets to a list w.r.t. multiple levels
      anchors_list = images_to_levels(all_anchors, num_level_anchors)
      labels_list = images_to_levels(all_labels, num_level_anchors)
      label_weights_list = images_to_levels(
          all_label_weights, num_level_anchors
      )
      bbox_targets_list = images_to_levels(
          all_bbox_targets, num_level_anchors
      )
      bbox_weights_list = images_to_levels(
          all_bbox_weights, num_level_anchors
      )
      return (
          anchors_list,
          labels_list,
          label_weights_list,
          bbox_targets_list,
          bbox_weights_list,
          num_total_pos,
          num_total_neg,
      )
  
imports: import torch
  import torch.nn
  import torch.nn.functional
  from mmcv.cnn import ConvModule, Scale, bias_init_with_prob, normal_init
  from mmcv.runner import force_fp32
  from mmdet.core import anchor_inside_flags, bbox2distance, bbox_overlaps, build_assigner, build_sampler, distance2bbox, images_to_levels, multi_apply, multiclass_nms, reduce_mean, unmap
  from ..builder import HEADS, build_loss
  from .anchor_head import AnchorHead
label_desc: Use image node_id 10 for calling the GFLHead obj's underlying member method code with example usage: obj.get_targets(anchor_list, valid_flag_list, gt_bboxes_list, img_metas, gt_bboxes_ignore_list, gt_labels_list, label_channels, unmap_outputs) and returns: anchors_list,  labels_list,  label_weights_list,  bbox_targets_list,  bbox_weights_list,  num_total_pos,  num_total_neg, None