class_docstr: Head of `VarifocalNet (VFNet): An IoU-aware Dense Object
  Detector.<https://arxiv.org/abs/2008.13367>`_.
  
  The VFNet predicts IoU-aware classification scores which mix the
  object presence confidence and object localization accuracy as the
  detection score. It is built on the FCOS architecture and uses ATSS
  for defining positive/negative training examples. The VFNet is trained
  with Varifocal Loss and empolys star-shaped deformable convolution to
  extract features for a bbox.
  
  Args:
      num_classes (int): Number of categories excluding the background
          category.
      in_channels (int): Number of channels in the input feature map.
      regress_ranges (Sequence[Tuple[int, int]]): Regress range of multiple
          level points.
      center_sampling (bool): If true, use center sampling. Defaults to False.
      center_sample_radius (float): Radius of center sampling. Defaults to 1.5.
      sync_num_pos (bool): If true, synchronize the number of positive
          examples across GPUs. Defaults to True
      gradient_mul (float): The multiplier to gradients from bbox refinement
          and recognition. Defaults to 0.1.
      bbox_norm_type (str): The bbox normalization type, 'reg_denom' or
          'stride'. Defaults to reg_denom
      loss_cls_fl (:obj:`ConfigDict` or dict): Config of focal loss.
      use_vfl (bool): If true, use varifocal loss for training.
          Defaults to True.
      loss_cls (:obj:`ConfigDict` or dict): Config of varifocal loss.
      loss_bbox (:obj:`ConfigDict` or dict): Config of localization loss,
          GIoU Loss.
      loss_bbox (:obj:`ConfigDict` or dict): Config of localization
          refinement loss, GIoU Loss.
      norm_cfg (:obj:`ConfigDict` or dict): dictionary to construct and
          config norm layer. Defaults to norm_cfg=dict(type='GN',
          num_groups=32, requires_grad=True).
      use_atss (bool): If true, use ATSS to define positive/negative
          examples. Defaults to True.
      anchor_generator (:obj:`ConfigDict` or dict): Config of anchor
          generator for ATSS.
      init_cfg (:obj:`ConfigDict` or dict or list[dict] or
          list[:obj:`ConfigDict`]): Initialization config dict.
  
  Example:
      >>> self = VFNetHead(11, 7)
      >>> feats = [torch.rand(1, 7, s, s) for s in [4, 8, 16, 32, 64]]
      >>> cls_score, bbox_pred, bbox_pred_refine= self.forward(feats)
      >>> assert len(cls_score) == len(self.scales)
class_docstr_tok: ["Head","of","`","VarifocalNet","(","VFNet",")",":","An","IoU-aware","Dense","Object","Detector.","<","https",":","\/\/arxiv.org\/abs\/2008.13367",">","`","_",".","The","VFNet","predicts","IoU-aware","classification","scores","which","mix","the","object","presence","confidence","and","object","localization","accuracy","as","the","detection","score",".","It","is","built","on","the","FCOS","architecture","and","uses","ATSS","for","defining","positive\/negative","training","examples",".","The","VFNet","is","trained","with","Varifocal","Loss","and","empolys","star-shaped","deformable","convolution","to","extract","features","for","a","bbox",".","Args",":","num_classes","(","int",")",":","Number","of","categories","excluding","the","background","category",".","in_channels","(","int",")",":","Number","of","channels","in","the","input","feature","map",".","regress_ranges","(","Sequence","[","Tuple","[","int",",","int","]","]",")",":","Regress","range","of","multiple","level","points",".","center_sampling","(","bool",")",":","If","true",",","use","center","sampling",".","Defaults","to","False",".","center_sample_radius","(","float",")",":","Radius","of","center","sampling",".","Defaults","to","1.5.","sync_num_pos","(","bool",")",":","If","true",",","synchronize","the","number","of","positive","examples","across","GPUs",".","Defaults","to","True","gradient_mul","(","float",")",":","The","multiplier","to","gradients","from","bbox","refinement","and","recognition",".","Defaults","to","0.1.","bbox_norm_type","(","str",")",":","The","bbox","normalization","type",",","'reg_denom","'","or","'stride","'",".","Defaults","to","reg_denom","loss_cls_fl","(",":","obj",":","`","ConfigDict","`","or","dict",")",":","Config","of","focal","loss",".","use_vfl","(","bool",")",":","If","true",",","use","varifocal","loss","for","training",".","Defaults","to","True",".","loss_cls","(",":","obj",":","`","ConfigDict","`","or","dict",")",":","Config","of","varifocal","loss",".","loss_bbox","(",":","obj",":","`","ConfigDict","`","or","dict",")",":","Config","of","localization","loss",",","GIoU","Loss",".","loss_bbox","(",":","obj",":","`","ConfigDict","`","or","dict",")",":","Config","of","localization","refinement","loss",",","GIoU","Loss",".","norm_cfg","(",":","obj",":","`","ConfigDict","`","or","dict",")",":","dictionary","to","construct","and","config","norm","layer",".","Defaults","to","norm_cfg=dict","(","type='GN","'",",","num_groups=32",",","requires_grad=True",")",".","use_atss","(","bool",")",":","If","true",",","use","ATSS","to","define","positive\/negative","examples",".","Defaults","to","True",".","anchor_generator","(",":","obj",":","`","ConfigDict","`","or","dict",")",":","Config","of","anchor","generator","for","ATSS",".","init_cfg","(",":","obj",":","`","ConfigDict","`","or","dict","or","list","[","dict","]","or","list","[",":","obj",":","`","ConfigDict","`","]",")",":","Initialization","config","dict",".","Example",":",">",">",">","self","=","VFNetHead","(","11",",","7",")",">",">",">","feats","=","[","torch.rand","(","1",",","7",",","s",",","s",")","for","s","in","[","4",",","8",",","16",",","32",",","64","]","]",">",">",">","cls_score",",","bbox_pred",",","bbox_pred_refine=","self.forward","(","feats",")",">",">",">","assert","len","(","cls_score",")","==","len","(","self.scales",")"]
docstr: Forward features of a single scale level.
  
  Args:
      x (Tensor): FPN feature maps of the specified stride.
      scale (:obj: `mmcv.cnn.Scale`): Learnable scale module to resize
          the bbox prediction.
      scale_refine (:obj: `mmcv.cnn.Scale`): Learnable scale module to
          resize the refined bbox prediction.
      stride (int): The corresponding stride for feature maps,
          used to normalize the bbox prediction when
          bbox_norm_type = 'stride'.
      reg_denom (int): The corresponding regression range for feature
          maps, only used to normalize the bbox prediction when
          bbox_norm_type = 'reg_denom'.
  
  Returns:
      tuple: iou-aware cls scores for each box, bbox predictions and
      refined bbox predictions of input feature maps.
docstr_tok: ["Forward","features","of","a","single","scale","level",".","Args",":","x","(","Tensor",")",":","FPN","feature","maps","of","the","specified","stride",".","scale","(",":","obj",":","`","mmcv.cnn.Scale","`",")",":","Learnable","scale","module","to","resize","the","bbox","prediction",".","scale_refine","(",":","obj",":","`","mmcv.cnn.Scale","`",")",":","Learnable","scale","module","to","resize","the","refined","bbox","prediction",".","stride","(","int",")",":","The","corresponding","stride","for","feature","maps",",","used","to","normalize","the","bbox","prediction","when","bbox_norm_type","=","'stride","'",".","reg_denom","(","int",")",":","The","corresponding","regression","range","for","feature","maps",",","only","used","to","normalize","the","bbox","prediction","when","bbox_norm_type","=","'reg_denom","'",".","Returns",":","tuple",":","iou-aware","cls","scores","for","each","box",",","bbox","predictions","and","refined","bbox","predictions","of","input","feature","maps","."]
code: def forward_single(
      self,
      x: Tensor,
      scale: Scale,
      scale_refine: Scale,
      stride: int,
      reg_denom: int,
  ) -> tuple:
      """Forward features of a single scale level.
  
      Args:
          x (Tensor): FPN feature maps of the specified stride.
          scale (:obj: `mmcv.cnn.Scale`): Learnable scale module to resize
              the bbox prediction.
          scale_refine (:obj: `mmcv.cnn.Scale`): Learnable scale module to
              resize the refined bbox prediction.
          stride (int): The corresponding stride for feature maps,
              used to normalize the bbox prediction when
              bbox_norm_type = 'stride'.
          reg_denom (int): The corresponding regression range for feature
              maps, only used to normalize the bbox prediction when
              bbox_norm_type = 'reg_denom'.
  
      Returns:
          tuple: iou-aware cls scores for each box, bbox predictions and
          refined bbox predictions of input feature maps.
      """
      cls_feat = x
      reg_feat = x
  
      for cls_layer in self.cls_convs:
          cls_feat = cls_layer(cls_feat)
  
      for reg_layer in self.reg_convs:
          reg_feat = reg_layer(reg_feat)
  
      # predict the bbox_pred of different level
      reg_feat_init = self.vfnet_reg_conv(reg_feat)
      if self.bbox_norm_type == "reg_denom":
          bbox_pred = (
              scale(self.vfnet_reg(reg_feat_init)).float().exp()
              * reg_denom
          )
      elif self.bbox_norm_type == "stride":
          bbox_pred = (
              scale(self.vfnet_reg(reg_feat_init)).float().exp()
              * stride
          )
      else:
          raise NotImplementedError
  
      # compute star deformable convolution offsets
      # converting dcn_offset to reg_feat.dtype thus VFNet can be
      # trained with FP16
      dcn_offset = self.star_dcn_offset(
          bbox_pred, self.gradient_mul, stride
      ).to(reg_feat.dtype)
  
      # refine the bbox_pred
      reg_feat = self.relu(
          self.vfnet_reg_refine_dconv(reg_feat, dcn_offset)
      )
      bbox_pred_refine = (
          scale_refine(self.vfnet_reg_refine(reg_feat)).float().exp()
      )
      bbox_pred_refine = bbox_pred_refine * bbox_pred.detach()
  
      # predict the iou-aware cls score
      cls_feat = self.relu(self.vfnet_cls_dconv(cls_feat, dcn_offset))
      cls_score = self.vfnet_cls(cls_feat)
  
      if self.training:
          return cls_score, bbox_pred, bbox_pred_refine
      else:
          return cls_score, bbox_pred_refine
  
imports: from typing import List, Tuple, Union
  import numpy
  import torch
  import torch.nn
  from mmcv.cnn import ConvModule, Scale
  from mmcv.ops import DeformConv2d
  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, OptInstanceList, RangeType, reduce_mean
  from ..task_modules.prior_generators import MlvlPointGenerator
  from ..task_modules.samplers import PseudoSampler
  from ..utils import multi_apply
  from .atss_head import ATSSHead
  from .fcos_head import FCOSHead
label_desc: Use image node_id 4 for calling the VFNetHead obj's underlying member method code with example usage: obj.forward_single(x, scale, scale_refine, stride, reg_denom) and returns: cls_score,  bbox_pred,  bbox_pred_refine, cls_score,  bbox_pred_refine