code: def test_setter(self):
      kie_data_sample = KIEDataSample()
      # test gt_instances
      gt_instances_data = dict(
          bboxes=torch.rand(4, 4),
          labels=torch.rand(4),
          texts=["t1", "t2", "t3", "t4"],
          relations=torch.rand(4, 4),
          edge_labels=torch.randint(0, 4, (4,)),
      )
      gt_instances = InstanceData(**gt_instances_data)
      kie_data_sample.gt_instances = gt_instances
      self.assertIn("gt_instances", kie_data_sample)
      self.assertTrue(
          self._equal(
              kie_data_sample.gt_instances.bboxes,
              gt_instances_data["bboxes"],
          )
      )
      self.assertTrue(
          self._equal(
              kie_data_sample.gt_instances.labels,
              gt_instances_data["labels"],
          )
      )
      self.assertTrue(
          self._equal(
              kie_data_sample.gt_instances.texts,
              gt_instances_data["texts"],
          )
      )
      self.assertTrue(
          self._equal(
              kie_data_sample.gt_instances.relations,
              gt_instances_data["relations"],
          )
      )
      self.assertTrue(
          self._equal(
              kie_data_sample.gt_instances.edge_labels,
              gt_instances_data["edge_labels"],
          )
      )
  
      # test pred_instances
      pred_instances_data = dict(
          bboxes=torch.rand(4, 4),
          labels=torch.rand(4),
          texts=["t1", "t2", "t3", "t4"],
          relations=torch.rand(4, 4),
          edge_labels=torch.randint(0, 4, (4,)),
      )
      pred_instances = InstanceData(**pred_instances_data)
      kie_data_sample.pred_instances = pred_instances
      assert "pred_instances" in kie_data_sample
      assert self._equal(
          kie_data_sample.pred_instances.bboxes,
          pred_instances_data["bboxes"],
      )
      assert self._equal(
          kie_data_sample.pred_instances.labels,
          pred_instances_data["labels"],
      )
      self.assertTrue(
          self._equal(
              kie_data_sample.pred_instances.texts,
              pred_instances_data["texts"],
          )
      )
      self.assertTrue(
          self._equal(
              kie_data_sample.pred_instances.relations,
              pred_instances_data["relations"],
          )
      )
      self.assertTrue(
          self._equal(
              kie_data_sample.pred_instances.edge_labels,
              pred_instances_data["edge_labels"],
          )
      )
  
      # test type error
      with self.assertRaises(AssertionError):
          kie_data_sample.gt_instances = torch.rand(2, 4)
      with self.assertRaises(AssertionError):
          kie_data_sample.pred_instances = torch.rand(2, 4)
  
file_path: mmocr/tests/test_structures/test_kie_data_sample.py
imports: from unittest import TestCase
  import numpy
  import torch
  from mmengine.structures import InstanceData
  from mmocr.structures import KIEDataSample
label_desc: Use image node_id 3 for calling the TestTextDetDataSample obj's underlying member method code with example usage: obj.test_setter() without return types