class_docstr: CenterNetUpdateHead is an improved version of CenterNet in CenterNet2.
  Paper link `<https://arxiv.org/abs/2103.07461>`_.
  
  Args:
      num_classes (int): Number of categories excluding the background
          category.
      in_channels (int): Number of channel in the input feature map.
      regress_ranges (Sequence[Tuple[int, int]]): Regress range of multiple
          level points.
      hm_min_radius (int): Heatmap target minimum radius of cls branch.
          Defaults to 4.
      hm_min_overlap (float): Heatmap target minimum overlap of cls branch.
          Defaults to 0.8.
      more_pos_thresh (float): The filtering threshold when the cls branch
          adds more positive samples. Defaults to 0.2.
      more_pos_topk (int): The maximum number of additional positive samples
          added to each gt. Defaults to 9.
      soft_weight_on_reg (bool): Whether to use the soft target of the
          cls branch as the soft weight of the bbox branch.
          Defaults to False.
      loss_cls (:obj:`ConfigDict` or dict): Config of cls loss. Defaults to
          dict(type='GaussianFocalLoss', loss_weight=1.0)
      loss_bbox (:obj:`ConfigDict` or dict): Config of bbox loss. Defaults to
           dict(type='GIoULoss', loss_weight=2.0).
      norm_cfg (:obj:`ConfigDict` or dict, optional): dictionary to construct
          and config norm layer.  Defaults to
          ``norm_cfg=dict(type='GN', num_groups=32, requires_grad=True)``.
      train_cfg (:obj:`ConfigDict` or dict, optional): Training config.
          Unused in CenterNet. Reserved for compatibility with
          SingleStageDetector.
      test_cfg (:obj:`ConfigDict` or dict, optional): Testing config
          of CenterNet.
docstr: Provide additional adaptive positive samples to the classification
  branch.
  
  Args:
      flatten_points (Tensor): The point after flatten, including
          batch image and all levels. The shape is (N, 2).
      flatten_bbox_preds (Tensor): The bbox predicts after flatten,
          including batch image and all levels. The shape is (N, 4).
      featmap_sizes (Tensor): Feature map size of all layers.
          The shape is (5, 2).
      batch_gt_instances (list[:obj:`InstanceData`]): Batch of
          gt_instance.  It usually includes ``bboxes`` and ``labels``
          attributes.
  
  Returns:
     tuple:
  
     - pos_inds (Tensor): Adaptively selected positive sample index.
     - cls_labels (Tensor): Corresponding positive class label.
docstr_tok: ["Provide","additional","adaptive","positive","samples","to","the","classification","branch",".","Args",":","flatten_points","(","Tensor",")",":","The","point","after","flatten",",","including","batch","image","and","all","levels",".","The","shape","is","(","N",",","2",")",".","flatten_bbox_preds","(","Tensor",")",":","The","bbox","predicts","after","flatten",",","including","batch","image","and","all","levels",".","The","shape","is","(","N",",","4",")",".","featmap_sizes","(","Tensor",")",":","Feature","map","size","of","all","layers",".","The","shape","is","(","5",",","2",")",".","batch_gt_instances","(","list","[",":","obj",":","`","InstanceData","`","]",")",":","Batch","of","gt_instance",".","It","usually","includes","``","bboxes","``","and","``","labels","``","attributes",".","Returns",":","tuple",":","-","pos_inds","(","Tensor",")",":","Adaptively","selected","positive","sample","index",".","-","cls_labels","(","Tensor",")",":","Corresponding","positive","class","label","."]
code: def add_cls_pos_inds(
      self,
      flatten_points: Tensor,
      flatten_bbox_preds: Tensor,
      featmap_sizes: Tensor,
      batch_gt_instances: InstanceList,
  ) -> Tuple[Optional[Tensor], Optional[Tensor]]:
      """Provide additional adaptive positive samples to the classification
      branch.
  
      Args:
          flatten_points (Tensor): The point after flatten, including
              batch image and all levels. The shape is (N, 2).
          flatten_bbox_preds (Tensor): The bbox predicts after flatten,
              including batch image and all levels. The shape is (N, 4).
          featmap_sizes (Tensor): Feature map size of all layers.
              The shape is (5, 2).
          batch_gt_instances (list[:obj:`InstanceData`]): Batch of
              gt_instance.  It usually includes ``bboxes`` and ``labels``
              attributes.
  
      Returns:
         tuple:
  
         - pos_inds (Tensor): Adaptively selected positive sample index.
         - cls_labels (Tensor): Corresponding positive class label.
      """
      outputs = self._get_center3x3_region_index_targets(
          batch_gt_instances, featmap_sizes
      )
      (
          cls_labels,
          fpn_level_masks,
          center3x3_inds,
          center3x3_bbox_targets,
          center3x3_masks,
      ) = outputs
  
      num_gts, total_level, K = (
          cls_labels.shape[0],
          len(self.strides),
          center3x3_masks.shape[-1],
      )
  
      if num_gts == 0:
          return None, None
  
      # The out-of-bounds index is forcibly set to 0
      # to prevent loss calculation errors
      center3x3_inds[center3x3_masks == 0] = 0
      reg_pred_center3x3 = flatten_bbox_preds[center3x3_inds]
      center3x3_points = flatten_points[center3x3_inds].view(-1, 2)
  
      center3x3_bbox_targets_expand = center3x3_bbox_targets.view(
          -1, 4
      ).clamp(min=0)
  
      pos_decoded_bbox_preds = self.bbox_coder.decode(
          center3x3_points, reg_pred_center3x3.view(-1, 4)
      )
      pos_decoded_target_preds = self.bbox_coder.decode(
          center3x3_points, center3x3_bbox_targets_expand
      )
      center3x3_bbox_loss = (
          self.loss_bbox(
              pos_decoded_bbox_preds,
              pos_decoded_target_preds,
              None,
              reduction_override="none",
          ).view(num_gts, total_level, K)
          / self.loss_bbox.loss_weight
      )
  
      # Invalid index Loss set to infinity
      center3x3_bbox_loss[center3x3_masks == 0] = INF
  
      # 4 is the center point of the sampled 9 points, the center point
      # of gt bbox after discretization.
      # The center point of gt bbox after discretization
      # must be a positive sample, so we force its loss to be set to 0.
      center3x3_bbox_loss.view(-1, K)[fpn_level_masks.view(-1), 4] = 0
      center3x3_bbox_loss = center3x3_bbox_loss.view(num_gts, -1)
  
      loss_thr = torch.kthvalue(
          center3x3_bbox_loss, self.more_pos_topk, dim=1
      )[0]
  
      loss_thr[loss_thr > self.more_pos_thresh] = self.more_pos_thresh
      new_pos = center3x3_bbox_loss < loss_thr.view(num_gts, 1)
      pos_inds = center3x3_inds.view(num_gts, -1)[new_pos]
      cls_labels = cls_labels.view(num_gts, 1).expand(
          num_gts, total_level * K
      )[new_pos]
      return pos_inds, cls_labels
  
imports: from typing import Dict, List, Optional, Sequence, Tuple
  import torch
  import torch.nn
  from mmcv.cnn import Scale
  from mmengine.structures import InstanceData
  from torch import Tensor
  from mmdet.registry import MODELS
  from mmdet.structures.bbox import bbox2distance
  from mmdet.utils import ConfigType, InstanceList, OptConfigType, OptInstanceList, reduce_mean
  from ..utils import multi_apply
  from .anchor_free_head import AnchorFreeHead
label_desc: Use image node_id 8 for calling the CenterNetUpdateHead obj's underlying member method code with example usage: obj.add_cls_pos_inds(flatten_points, flatten_bbox_preds, featmap_sizes, batch_gt_instances) and returns: pos_inds,  cls_labels, None,  None