code: def test_get_targets(self):
      # test get_targets
      loss = DRRGModuleLoss(
          min_width=2.0,
          max_width=4.0,
          min_rand_half_height=3.0,
          max_rand_half_height=5.0,
      )
      targets = loss.get_targets(self.data_samples)
      for target in targets[:-1]:
          self.assertEqual(len(target), 1)
      self.assertEqual(targets[-1][0].shape[-1], 8)
  
      # test generate_targets with blank polygon masks
      blank_data_samples = [
          TextDetDataSample(
              metainfo=dict(img_shape=(20, 20)),
              gt_instances=InstanceData(
                  polygons=[], ignored=torch.BoolTensor([])
              ),
          )
      ]
      targets = loss.get_targets(blank_data_samples)
      self.assertGreater(targets[-1][0][0, 0], 8)
  
      # test get_targets with the number of proposed text components exceeds
      # num_max_comps
      loss = DRRGModuleLoss(
          min_width=2.0,
          max_width=4.0,
          min_rand_half_height=3.0,
          max_rand_half_height=5.0,
          num_max_comps=6,
      )
      targets = loss.get_targets(self.data_samples)
      self.assertEqual(targets[-1][0].ndim, 2)
      self.assertEqual(targets[-1][0].shape[0], 6)
  
      # test generate_targets with one proposed text component
      data_samples = [
          TextDetDataSample(
              metainfo=dict(img_shape=(20, 30)),
              gt_instances=InstanceData(
                  polygons=[np.array([13, 6, 17, 6, 17, 14, 13, 14])],
                  ignored=torch.BoolTensor([False]),
              ),
          )
      ]
      loss = DRRGModuleLoss(
          min_width=4.0,
          max_width=8.0,
          min_rand_half_height=3.0,
          max_rand_half_height=5.0,
      )
      targets = loss.get_targets(data_samples)
      self.assertGreater(targets[-1][0][0, 0], 8)
  
      # test generate_targets with shrunk margin in
      # generate_rand_comp_attribs
      loss = DRRGModuleLoss(
          min_width=2.0,
          max_width=30.0,
          min_rand_half_height=3.0,
          max_rand_half_height=30.0,
      )
      targets = loss.get_targets(data_samples)
      self.assertGreater(targets[-1][0][0, 0], 8)
  
file_path: mmocr/tests/test_models/test_textdet/test_module_losses/test_drrg_module_loss.py
imports: from unittest import TestCase
  import numpy
  import torch
  from mmengine.structures import InstanceData
  from mmocr.models.textdet.module_losses import DRRGModuleLoss
  from mmocr.structures import TextDetDataSample
label_desc: Use image node_id 3 for calling the TestDRRGModuleLoss obj's underlying member method code with example usage: obj.test_get_targets() without return types