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: Forward feature of a single scale level.
  
  Args:
      x (Tensor): Features of a single scale level.
      scale (:obj: `mmcv.cnn.Scale`): Learnable scale module to resize
          the bbox prediction.
  
  Returns:
      tuple:
          cls_score (Tensor): Cls and quality joint scores for a single
              scale level the channel number is num_classes.
          bbox_pred (Tensor): Box distribution logits for a single scale
              level, the channel number is 4*(n+1), n is max value of
              integral set.
docstr_tok: ["Forward","feature","of","a","single","scale","level",".","Args",":","x","(","Tensor",")",":","Features","of","a","single","scale","level",".","scale","(",":","obj",":","`","mmcv.cnn.Scale","`",")",":","Learnable","scale","module","to","resize","the","bbox","prediction",".","Returns",":","tuple",":","cls_score","(","Tensor",")",":","Cls","and","quality","joint","scores","for","a","single","scale","level","the","channel","number","is","num_classes",".","bbox_pred","(","Tensor",")",":","Box","distribution","logits","for","a","single","scale","level",",","the","channel","number","is","4","*","(","n+1",")",",","n","is","max","value","of","integral","set","."]
code: def forward_single(self, x, scale, stride):
      """Forward feature of a single scale level.
  
      Args:
          x (Tensor): Features of a single scale level.
          scale (:obj: `mmcv.cnn.Scale`): Learnable scale module to resize
              the bbox prediction.
  
      Returns:
          tuple:
              cls_score (Tensor): Cls and quality joint scores for a single
                  scale level the channel number is num_classes.
              bbox_pred (Tensor): Box distribution logits for a single scale
                  level, the channel number is 4*(n+1), n is max value of
                  integral set.
      """
      cls_feat = x
      reg_feat = x
      # print('forward_single in stride:', stride)
      cls_convs = (
          self.cls_stride_convs["0"]
          if self.strides_share
          else self.cls_stride_convs[str(stride)]
      )
      for cls_conv in cls_convs:
          cls_feat = cls_conv(cls_feat)
      if not self.cls_reg_share:
          reg_convs = (
              self.reg_stride_convs["0"]
              if self.strides_share
              else self.reg_stride_convs[str(stride)]
          )
          for reg_conv in reg_convs:
              reg_feat = reg_conv(reg_feat)
      else:
          reg_feat = cls_feat
      cls_pred_module = (
          self.stride_cls["0"]
          if self.strides_share
          else self.stride_cls[str(stride)]
      )
      cls_score = cls_pred_module(cls_feat)
      reg_pred_module = (
          self.stride_reg["0"]
          if self.strides_share
          else self.stride_reg[str(stride)]
      )
      _bbox_pred = reg_pred_module(reg_feat)
      if self.use_scale:
          bbox_pred = scale(_bbox_pred)
      else:
          bbox_pred = _bbox_pred
      if self.use_kps:
          kps_pred_module = (
              self.stride_kps["0"]
              if self.strides_share
              else self.stride_kps[str(stride)]
          )
          kps_pred = kps_pred_module(reg_feat)
      else:
          kps_pred = bbox_pred.new_zeros(
              (
                  bbox_pred.shape[0],
                  self.NK * 2,
                  bbox_pred.shape[2],
                  bbox_pred.shape[3],
              )
          )
      if torch.onnx.is_in_onnx_export():
          assert not self.use_dfl
          print("in-onnx-export", cls_score.shape, bbox_pred.shape)
          # print(scale.parameters())
          # for p in scale.parameters():
          # print(p.name, p.data)
          # scale_val = p.data.item()
          # print(scale_val)
          # print('EEE1', cls_score.shape)
          # cls_score = torch.sigmoid(cls_score).reshape(1, self.cls_out_channels, -1).permute(0, 2, 1)
          # print('EEE2', cls_score.shape)
          # if self.use_dfl:
          #    bbox_pred = self.integral(bbox_pred) * stride[0]
          # else:
          #    bbox_pred = bbox_pred.reshape( (-1,4) ) * stride[0]
          # if self.use_dfl:
          #    bbox_pred = bbox_pred.reshape(1, (self.reg_max+1)*4, -1).permute(0, 2, 1)
          #    bbox_pred = bbox_pred.reshape( (1, -1, 4, self.reg_max+1) )
          #    bbox_pred = F.softmax(bbox_pred, dim=3)
          # else:
          #    bbox_pred = bbox_pred.reshape(1, 4, -1).permute(0, 2, 1)
          # kps_pred = kps_pred.reshape(1, 10, -1).permute(0, 2, 1)
  
          # Add output batch dim, based on pull request #1593
          batch_size = cls_score.shape[0]
          cls_score = (
              cls_score.permute(0, 2, 3, 1)
              .reshape(batch_size, -1, self.cls_out_channels)
              .sigmoid()
          )
          bbox_pred = bbox_pred.permute(0, 2, 3, 1).reshape(
              batch_size, -1, 4
          )
          kps_pred = kps_pred.permute(0, 2, 3, 1).reshape(
              batch_size, -1, 10
          )
  
      return cls_score, bbox_pred, kps_pred
  
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 6 for calling the SCRFDHead obj's underlying member method code with example usage: obj.forward_single(x, scale, stride) and returns: cls_score,  bbox_pred,  kps_pred