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.
          Defaults to 4.
      conv_cfg (:obj:`ConfigDict` or dict, optional): dictionary to construct
          and config conv layer. Defaults to None.
      norm_cfg (:obj:`ConfigDict` or dict): dictionary to construct and
          config norm layer. Default: dict(type='GN', num_groups=32,
          requires_grad=True).
      loss_qfl (:obj:`ConfigDict` or dict): Config of Quality Focal Loss
          (QFL).
      bbox_coder (:obj:`ConfigDict` or dict): Config of bbox coder. Defaults
           to 'DistancePointBBoxCoder'.
      reg_max (int): Max value of integral set :math: ``{0, ..., reg_max}``
          in QFL setting. Defaults to 16.
      init_cfg (:obj:`ConfigDict` or dict or list[dict] or
          list[:obj:`ConfigDict`]): Initialization config dict.
  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",".","Defaults","to","4.","conv_cfg","(",":","obj",":","`","ConfigDict","`","or","dict",",","optional",")",":","dictionary","to","construct","and","config","conv","layer",".","Defaults","to","None",".","norm_cfg","(",":","obj",":","`","ConfigDict","`","or","dict",")",":","dictionary","to","construct","and","config","norm","layer",".","Default",":","dict","(","type='GN","'",",","num_groups=32",",","requires_grad=True",")",".","loss_qfl","(",":","obj",":","`","ConfigDict","`","or","dict",")",":","Config","of","Quality","Focal","Loss","(","QFL",")",".","bbox_coder","(",":","obj",":","`","ConfigDict","`","or","dict",")",":","Config","of","bbox","coder",".","Defaults","to","'DistancePointBBoxCoder","'",".","reg_max","(","int",")",":","Max","value","of","integral","set",":","math",":","``","{","0",",","...",",","reg_max","}","``","in","QFL","setting",".","Defaults","to","16.","init_cfg","(",":","obj",":","`","ConfigDict","`","or","dict","or","list","[","dict","]","or","list","[",":","obj",":","`","ConfigDict","`","]",")",":","Initialization","config","dict",".","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: List[Tensor],
      valid_flag_list: List[Tensor],
      batch_gt_instances: InstanceList,
      batch_img_metas: List[dict],
      batch_gt_instances_ignore: OptInstanceList = None,
      unmap_outputs=True,
  ) -> tuple:
      """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(batch_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 batch_gt_instances_ignore is None:
          batch_gt_instances_ignore = [None] * num_imgs
      (
          all_anchors,
          all_labels,
          all_label_weights,
          all_bbox_targets,
          all_bbox_weights,
          pos_inds_list,
          neg_inds_list,
          sampling_results_list,
      ) = multi_apply(
          self._get_targets_single,
          anchor_list,
          valid_flag_list,
          num_level_anchors_list,
          batch_gt_instances,
          batch_img_metas,
          batch_gt_instances_ignore,
          unmap_outputs=unmap_outputs,
      )
      # Get `avg_factor` of all images, which calculate in `SamplingResult`.
      # When using sampling method, avg_factor is usually the sum of
      # positive and negative priors. When using `PseudoSampler`,
      # `avg_factor` is usually equal to the number of positive priors.
      avg_factor = sum(
          [results.avg_factor for results in sampling_results_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,
          avg_factor,
      )
  
imports: from typing import List, Optional, Sequence, Tuple
  import torch
  import torch.nn
  import torch.nn.functional
  from mmcv.cnn import ConvModule, Scale
  from mmengine.config import ConfigDict
  from mmengine.structures import InstanceData
  from torch import Tensor
  from mmdet.registry import MODELS, TASK_UTILS
  from mmdet.structures.bbox import bbox_overlaps
  from mmdet.utils import ConfigType, InstanceList, MultiConfig, OptConfigType, OptInstanceList, reduce_mean
  from ..task_modules.prior_generators import anchor_inside_flags
  from ..task_modules.samplers import PseudoSampler
  from ..utils import filter_scores_and_topk, images_to_levels, multi_apply, unmap
  from .anchor_head import AnchorHead
label_desc: Use image node_id 9 for calling the GFLHead obj's underlying member method code with example usage: obj.get_targets(anchor_list, valid_flag_list, batch_gt_instances, batch_img_metas, batch_gt_instances_ignore, unmap_outputs) and returns: anchors_list,  labels_list,  label_weights_list,  bbox_targets_list,  bbox_weights_list,  avg_factor