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 (tuple[tuple[int, int]]): Regress range of multiple
          level points.
      center_sampling (bool): If true, use center sampling. Default: False.
      center_sample_radius (float): Radius of center sampling. Default: 1.5.
      sync_num_pos (bool): If true, synchronize the number of positive
          examples across GPUs. Default: True
      gradient_mul (float): The multiplier to gradients from bbox refinement
          and recognition. Default: 0.1.
      bbox_norm_type (str): The bbox normalization type, 'reg_denom' or
          'stride'. Default: reg_denom
      loss_cls_fl (dict): Config of focal loss.
      use_vfl (bool): If true, use varifocal loss for training.
          Default: True.
      loss_cls (dict): Config of varifocal loss.
      loss_bbox (dict): Config of localization loss, GIoU Loss.
      loss_bbox (dict): Config of localization refinement loss, GIoU Loss.
      norm_cfg (dict): dictionary to construct and config norm layer.
          Default: norm_cfg=dict(type='GN', num_groups=32,
          requires_grad=True).
      use_atss (bool): If true, use ATSS to define positive/negative
          examples. Default: True.
      anchor_generator (dict): Config of anchor generator for ATSS.
  
  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)
code: def __init__(
      self,
      num_classes,
      in_channels,
      regress_ranges=(
          (-1, 64),
          (64, 128),
          (128, 256),
          (256, 512),
          (512, INF),
      ),
      center_sampling=False,
      center_sample_radius=1.5,
      sync_num_pos=True,
      gradient_mul=0.1,
      bbox_norm_type="reg_denom",
      loss_cls_fl=dict(
          type="FocalLoss",
          use_sigmoid=True,
          gamma=2.0,
          alpha=0.25,
          loss_weight=1.0,
      ),
      use_vfl=True,
      loss_cls=dict(
          type="VarifocalLoss",
          use_sigmoid=True,
          alpha=0.75,
          gamma=2.0,
          iou_weighted=True,
          loss_weight=1.0,
      ),
      loss_bbox=dict(type="GIoULoss", loss_weight=1.5),
      loss_bbox_refine=dict(type="GIoULoss", loss_weight=2.0),
      norm_cfg=dict(type="GN", num_groups=32, requires_grad=True),
      use_atss=True,
      anchor_generator=dict(
          type="AnchorGenerator",
          ratios=[1.0],
          octave_base_scale=8,
          scales_per_octave=1,
          center_offset=0.0,
          strides=[8, 16, 32, 64, 128],
      ),
      **kwargs,
  ):
      # dcn base offsets, adapted from reppoints_head.py
      self.num_dconv_points = 9
      self.dcn_kernel = int(np.sqrt(self.num_dconv_points))
      self.dcn_pad = int((self.dcn_kernel - 1) / 2)
      dcn_base = np.arange(-self.dcn_pad, self.dcn_pad + 1).astype(
          np.float64
      )
      dcn_base_y = np.repeat(dcn_base, self.dcn_kernel)
      dcn_base_x = np.tile(dcn_base, self.dcn_kernel)
      dcn_base_offset = np.stack(
          [dcn_base_y, dcn_base_x], axis=1
      ).reshape((-1))
      self.dcn_base_offset = torch.tensor(dcn_base_offset).view(
          1, -1, 1, 1
      )
  
      super(FCOSHead, self).__init__(
          num_classes, in_channels, norm_cfg=norm_cfg, **kwargs
      )
      self.regress_ranges = regress_ranges
      self.reg_denoms = [
          regress_range[-1] for regress_range in regress_ranges
      ]
      self.reg_denoms[-1] = self.reg_denoms[-2] * 2
      self.center_sampling = center_sampling
      self.center_sample_radius = center_sample_radius
      self.sync_num_pos = sync_num_pos
      self.bbox_norm_type = bbox_norm_type
      self.gradient_mul = gradient_mul
      self.use_vfl = use_vfl
      if self.use_vfl:
          self.loss_cls = build_loss(loss_cls)
      else:
          self.loss_cls = build_loss(loss_cls_fl)
      self.loss_bbox = build_loss(loss_bbox)
      self.loss_bbox_refine = build_loss(loss_bbox_refine)
  
      # for getting ATSS targets
      self.use_atss = use_atss
      self.use_sigmoid_cls = loss_cls.get("use_sigmoid", False)
      self.anchor_generator = build_anchor_generator(anchor_generator)
      self.anchor_center_offset = anchor_generator["center_offset"]
      self.num_anchors = self.anchor_generator.num_base_anchors[0]
      self.sampling = False
      if self.train_cfg:
          self.assigner = build_assigner(self.train_cfg.assigner)
          sampler_cfg = dict(type="PseudoSampler")
          self.sampler = build_sampler(sampler_cfg, context=self)
  
imports: import numpy
  import torch
  import torch.nn
  from mmcv.cnn import ConvModule, Scale, bias_init_with_prob, normal_init
  from mmcv.ops import DeformConv2d
  from mmcv.runner import force_fp32
  from mmdet.core import bbox2distance, bbox_overlaps, build_anchor_generator, build_assigner, build_sampler, distance2bbox, multi_apply, multiclass_nms, reduce_mean
  from ..builder import HEADS, build_loss
  from .atss_head import ATSSHead
  from .fcos_head import FCOSHead
label_desc: Use image node_id 1 to create a new VFNetHead object from inherited base classes: ATSSHead, FCOSHead with example: obj = VFNetHead(num_classes, in_channels, regress_ranges, center_sampling, center_sample_radius, sync_num_pos, gradient_mul, bbox_norm_type, loss_cls_fl, use_vfl, loss_cls, loss_bbox, loss_bbox_refine, norm_cfg, use_atss, anchor_generator)