docstr: Tests center head generating and decoding the heatmap.
docstr_tok: ["Tests","center","head","generating","and","decoding","the","heatmap","."]
code: def test_centernet_head_get_targets(self):
      """Tests center head generating and decoding the heatmap."""
      s = 256
      img_metas = [
          {
              "img_shape": (s, s, 3),
              "batch_input_shape": (s, s),
          }
      ]
      test_cfg = ConfigDict(
          dict(topk=100, local_maximum_kernel=3, max_per_img=100)
      )
      gt_bboxes = [
          torch.Tensor(
              [
                  [10, 20, 200, 240],
                  [40, 50, 100, 200],
                  [10, 20, 100, 240],
              ]
          )
      ]
      gt_labels = [torch.LongTensor([1, 1, 2])]
  
      centernet_head = CenterNetHead(
          num_classes=4,
          in_channels=1,
          feat_channels=4,
          test_cfg=test_cfg,
      )
      self.feat_shape = (1, 1, s // 4, s // 4)
      targets, _ = centernet_head.get_targets(
          gt_bboxes,
          gt_labels,
          self.feat_shape,
          img_metas[0]["img_shape"],
      )
      center_target = targets["center_heatmap_target"]
      wh_target = targets["wh_target"]
      offset_target = targets["offset_target"]
      # make sure assign target right
      for i in range(len(gt_bboxes[0])):
          bbox, label = gt_bboxes[0][i] / 4, gt_labels[0][i]
          ctx, cty = sum(bbox[0::2]) / 2, sum(bbox[1::2]) / 2
          int_ctx, int_cty = int(sum(bbox[0::2]) / 2), int(
              sum(bbox[1::2]) / 2
          )
          w, h = bbox[2] - bbox[0], bbox[3] - bbox[1]
          x_off = ctx - int(ctx)
          y_off = cty - int(cty)
          assert center_target[0, label, int_cty, int_ctx] == 1
          assert wh_target[0, 0, int_cty, int_ctx] == w
          assert wh_target[0, 1, int_cty, int_ctx] == h
          assert offset_target[0, 0, int_cty, int_ctx] == x_off
          assert offset_target[0, 1, int_cty, int_ctx] == y_off
  
file_path: mmdetection/tests/test_models/test_dense_heads/test_centernet_head.py
imports: from unittest import TestCase
  import torch
  from mmengine.config import ConfigDict
  from mmengine.structures import InstanceData
  from mmdet.models.dense_heads import CenterNetHead
label_desc: Use image node_id 2 for calling the TestCenterNetHead obj's underlying member method code with example usage: obj.test_centernet_head_get_targets() without return types