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: Args:
      x (list[Tensor]): Features from FPN.
      img_metas (list[dict]): Meta information of each image, e.g.,
          image size, scaling factor, etc.
      gt_bboxes (Tensor): Ground truth bboxes of the image,
          shape (num_gts, 4).
      gt_labels (Tensor): Ground truth labels of each box,
          shape (num_gts,).
      gt_bboxes_ignore (Tensor): Ground truth bboxes to be
          ignored, shape (num_ignored_gts, 4).
      proposal_cfg (mmcv.Config): Test / postprocessing configuration,
          if None, test_cfg would be used
  
  Returns:
      tuple:
          losses: (dict[str, Tensor]): A dictionary of loss components.
          proposal_list (list[Tensor]): Proposals of each image.
docstr_tok: ["Args",":","x","(","list","[","Tensor","]",")",":","Features","from","FPN",".","img_metas","(","list","[","dict","]",")",":","Meta","information","of","each","image",",","e.g.",",","image","size",",","scaling","factor",",","etc",".","gt_bboxes","(","Tensor",")",":","Ground","truth","bboxes","of","the","image",",","shape","(","num_gts",",","4",")",".","gt_labels","(","Tensor",")",":","Ground","truth","labels","of","each","box",",","shape","(","num_gts",",",")",".","gt_bboxes_ignore","(","Tensor",")",":","Ground","truth","bboxes","to","be","ignored",",","shape","(","num_ignored_gts",",","4",")",".","proposal_cfg","(","mmcv.Config",")",":","Test","\/","postprocessing","configuration",",","if","None",",","test_cfg","would","be","used","Returns",":","tuple",":","losses",":","(","dict","[","str",",","Tensor","]",")",":","A","dictionary","of","loss","components",".","proposal_list","(","list","[","Tensor","]",")",":","Proposals","of","each","image","."]
code: def forward_train(
      self,
      x,
      img_metas,
      gt_bboxes,
      gt_labels=None,
      gt_keypointss=None,
      gt_bboxes_ignore=None,
      proposal_cfg=None,
      **kwargs,
  ):
      """
      Args:
          x (list[Tensor]): Features from FPN.
          img_metas (list[dict]): Meta information of each image, e.g.,
              image size, scaling factor, etc.
          gt_bboxes (Tensor): Ground truth bboxes of the image,
              shape (num_gts, 4).
          gt_labels (Tensor): Ground truth labels of each box,
              shape (num_gts,).
          gt_bboxes_ignore (Tensor): Ground truth bboxes to be
              ignored, shape (num_ignored_gts, 4).
          proposal_cfg (mmcv.Config): Test / postprocessing configuration,
              if None, test_cfg would be used
  
      Returns:
          tuple:
              losses: (dict[str, Tensor]): A dictionary of loss components.
              proposal_list (list[Tensor]): Proposals of each image.
      """
      outs = self(x)
      if gt_labels is None:
          loss_inputs = outs + (gt_bboxes, img_metas)
      else:
          loss_inputs = outs + (
              gt_bboxes,
              gt_labels,
              gt_keypointss,
              img_metas,
          )
      # print('AAA', gt_bboxes[0].shape, gt_keypointss[0].shape)
      losses = self.loss(
          *loss_inputs, gt_bboxes_ignore=gt_bboxes_ignore
      )
      if proposal_cfg is None:
          return losses
      else:
          proposal_list = self.get_bboxes(
              *outs, img_metas, cfg=proposal_cfg
          )
          return losses, proposal_list
  
imports: import numpy
  import torch
  import torch.nn
  import torch.nn.functional
  from mmcv.cnn import ConvModule, Scale, bias_init_with_prob, normal_init, DepthwiseSeparableConvModule
  from mmcv.cnn import constant_init, kaiming_init
  from mmcv.runner import force_fp32
  from mmdet.core import anchor_inside_flags, bbox2distance, bbox_overlaps, build_assigner, build_sampler, distance2bbox, distance2kps, kps2distance, images_to_levels, multi_apply, multiclass_nms, reduce_mean, unmap
  from ..builder import HEADS, build_loss
  from .anchor_head import AnchorHead
  from .base_dense_head import BaseDenseHead
  from .dense_test_mixins import BBoxTestMixin
label_desc: Use image node_id 7 for calling the SCRFDHead obj's underlying member method code with example usage: obj.forward_train(x, img_metas, gt_bboxes, gt_labels, gt_keypointss, gt_bboxes_ignore, proposal_cfg) and returns: losses, losses,  proposal_list