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: Get the center (and the 3x3 region near center) locations and target
  of each objects.
docstr_tok: ["Get","the","center","(","and","the","3x3","region","near","center",")","locations","and","target","of","each","objects","."]
code: def _get_center3x3_region_index_targets(
      self, bacth_gt_instances: InstanceList, shapes_per_level: Tensor
  ) -> tuple:
      """Get the center (and the 3x3 region near center) locations and target
      of each objects."""
      cls_labels = []
      inside_fpn_level_masks = []
      center3x3_inds = []
      center3x3_masks = []
      center3x3_bbox_targets = []
  
      total_levels = len(self.strides)
      batch = len(bacth_gt_instances)
  
      shapes_per_level = shapes_per_level.long()
      area_per_level = shapes_per_level[:, 0] * shapes_per_level[:, 1]
  
      # Select a total of 9 positions of 3x3 in the center of the gt bbox
      # as candidate positive samples
      K = 9
      dx = shapes_per_level.new_tensor(
          [-1, 0, 1, -1, 0, 1, -1, 0, 1]
      ).view(1, 1, K)
      dy = shapes_per_level.new_tensor(
          [-1, -1, -1, 0, 0, 0, 1, 1, 1]
      ).view(1, 1, K)
  
      regress_ranges = shapes_per_level.new_tensor(
          self.regress_ranges
      ).view(
          len(self.regress_ranges), 2
      )  # L x 2
      strides = shapes_per_level.new_tensor(self.strides)
  
      start_coord_pre_level = []
      _start = 0
      for level in range(total_levels):
          start_coord_pre_level.append(_start)
          _start = _start + batch * area_per_level[level]
      start_coord_pre_level = shapes_per_level.new_tensor(
          start_coord_pre_level
      ).view(1, total_levels, 1)
      area_per_level = area_per_level.view(1, total_levels, 1)
  
      for im_i in range(batch):
          gt_instance = bacth_gt_instances[im_i]
          gt_bboxes = gt_instance.bboxes
          gt_labels = gt_instance.labels
          num_gts = gt_bboxes.shape[0]
          if num_gts == 0:
              continue
  
          cls_labels.append(gt_labels)
  
          gt_bboxes = gt_bboxes[:, None].expand(
              num_gts, total_levels, 4
          )
          expanded_strides = strides[None, :, None].expand(
              num_gts, total_levels, 2
          )
          expanded_regress_ranges = regress_ranges[None].expand(
              num_gts, total_levels, 2
          )
          expanded_shapes_per_level = shapes_per_level[None].expand(
              num_gts, total_levels, 2
          )
  
          # calc reg_target
          centers = (
              gt_bboxes[..., [0, 1]] + gt_bboxes[..., [2, 3]]
          ) / 2
          centers_inds = (centers / expanded_strides).long()
          centers_discret = (
              centers_inds * expanded_strides + expanded_strides // 2
          )
  
          bbox_target = bbox2distance(
              centers_discret, gt_bboxes
          )  # M x N x 4
  
          # calc inside_fpn_level_mask
          bbox_target_wh = bbox_target[..., :2] + bbox_target[..., 2:]
          crit = (bbox_target_wh**2).sum(dim=2) ** 0.5 / 2
          inside_fpn_level_mask = (
              crit >= expanded_regress_ranges[..., 0]
          ) & (crit <= expanded_regress_ranges[..., 1])
  
          inside_gt_bbox_mask = bbox_target.min(dim=2)[0] >= 0
          inside_fpn_level_mask = (
              inside_gt_bbox_mask & inside_fpn_level_mask
          )
          inside_fpn_level_masks.append(inside_fpn_level_mask)
  
          # calc center3x3_ind and mask
          expand_ws = expanded_shapes_per_level[..., 1:2].expand(
              num_gts, total_levels, K
          )
          expand_hs = expanded_shapes_per_level[..., 0:1].expand(
              num_gts, total_levels, K
          )
          centers_inds_x = centers_inds[..., 0:1]
          centers_inds_y = centers_inds[..., 1:2]
  
          center3x3_idx = (
              start_coord_pre_level
              + im_i * area_per_level
              + (centers_inds_y + dy) * expand_ws
              + (centers_inds_x + dx)
          )
          center3x3_mask = (
              ((centers_inds_y + dy) < expand_hs)
              & ((centers_inds_y + dy) >= 0)
              & ((centers_inds_x + dx) < expand_ws)
              & ((centers_inds_x + dx) >= 0)
          )
  
          # recalc center3x3 region reg target
          bbox_target = bbox_target / expanded_strides.repeat(1, 1, 2)
          center3x3_bbox_target = (
              bbox_target[..., None, :]
              .expand(num_gts, total_levels, K, 4)
              .clone()
          )
          center3x3_bbox_target[..., 0] += dx
          center3x3_bbox_target[..., 1] += dy
          center3x3_bbox_target[..., 2] -= dx
          center3x3_bbox_target[..., 3] -= dy
          # update center3x3_mask
          center3x3_mask = center3x3_mask & (
              center3x3_bbox_target.min(dim=3)[0] >= 0
          )  # n x L x K
  
          center3x3_inds.append(center3x3_idx)
          center3x3_masks.append(center3x3_mask)
          center3x3_bbox_targets.append(center3x3_bbox_target)
  
      if len(inside_fpn_level_masks) > 0:
          cls_labels = torch.cat(cls_labels, dim=0)
          inside_fpn_level_masks = torch.cat(
              inside_fpn_level_masks, dim=0
          )
          center3x3_inds = torch.cat(center3x3_inds, dim=0).long()
          center3x3_bbox_targets = torch.cat(
              center3x3_bbox_targets, dim=0
          )
          center3x3_masks = torch.cat(center3x3_masks, dim=0)
      else:
          cls_labels = shapes_per_level.new_zeros(0).long()
          inside_fpn_level_masks = shapes_per_level.new_zeros(
              (0, total_levels)
          ).bool()
          center3x3_inds = shapes_per_level.new_zeros(
              (0, total_levels, K)
          ).long()
          center3x3_bbox_targets = shapes_per_level.new_zeros(
              (0, total_levels, K, 4)
          ).float()
          center3x3_masks = shapes_per_level.new_zeros(
              (0, total_levels, K)
          ).bool()
      return (
          cls_labels,
          inside_fpn_level_masks,
          center3x3_inds,
          center3x3_bbox_targets,
          center3x3_masks,
      )
  
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 10 for calling the CenterNetUpdateHead obj's underlying member method code with example usage: obj._get_center3x3_region_index_targets(bacth_gt_instances, shapes_per_level) and returns: cls_labels,  inside_fpn_level_masks,  center3x3_inds,  center3x3_bbox_targets,  center3x3_masks