code: def test_anchor_2d(
      self, input_param, image_shape, feature_maps_shapes
  ):
      torch_anchor_utils, _ = optional_import(
          "torchvision.models.detection.anchor_utils"
      )
      image_list, _ = optional_import(
          "torchvision.models.detection.image_list"
      )
  
      # test it behaves the same with torchvision for 2d
      anchor = AnchorGenerator(**input_param, indexing="xy")
      anchor_ref = torch_anchor_utils.AnchorGenerator(**input_param)
      for a, a_f in zip(anchor.cell_anchors, anchor_ref.cell_anchors):
          assert_allclose(
              a, a_f, type_test=True, device_test=False, atol=1e-3
          )
      for a, a_f in zip(
          anchor.num_anchors_per_location(),
          anchor_ref.num_anchors_per_location(),
      ):
          assert_allclose(
              a, a_f, type_test=True, device_test=False, atol=1e-3
          )
  
      grid_sizes = [[2, 2], [1, 1]]
      strides = [
          [torch.tensor(1), torch.tensor(2)],
          [torch.tensor(2), torch.tensor(4)],
      ]
      for a, a_f in zip(
          anchor.grid_anchors(grid_sizes, strides),
          anchor_ref.grid_anchors(grid_sizes, strides),
      ):
          assert_allclose(
              a, a_f, type_test=True, device_test=False, atol=1e-3
          )
  
      images = torch.rand(image_shape)
      feature_maps = tuple(torch.rand(fs) for fs in feature_maps_shapes)
      result = anchor(images, feature_maps)
      result_ref = anchor_ref(
          image_list.ImageList(images, ([123, 122],)), feature_maps
      )
      for a, a_f in zip(result, result_ref):
          assert_allclose(
              a, a_f, type_test=True, device_test=False, atol=0.1
          )
  
file_path: MONAI/tests/test_anchor_box.py
imports: from __future__ import annotations
  import unittest
  import torch
  from parameterized import parameterized
  from monai.apps.detection.utils.anchor_utils import AnchorGenerator, AnchorGeneratorWithAnchorShape
  from monai.utils import optional_import
  from tests.utils import SkipIfBeforePyTorchVersion, assert_allclose, test_script_save
label_desc: Use image node_id 1 for calling the TestAnchorGenerator obj's underlying member method code with example usage: obj.test_anchor_2d(input_param, image_shape, feature_maps_shapes) without return types