code: def test_set_gt_score(self):
      data_sample = ReIDDataSample(metainfo={"num_classes": 5})
      method = getattr(data_sample, "set_" + "gt_score")
  
      # Test set
      score = [0.1, 0.1, 0.6, 0.1, 0.1]
      method(torch.tensor(score))
      sample_gt_label = getattr(data_sample, "gt_label")
      self.assertIn("score", sample_gt_label)
      torch.testing.assert_allclose(sample_gt_label.score, score)
      self.assertEqual(sample_gt_label.num_classes, 5)
  
      # Test set again
      score = [0.2, 0.1, 0.5, 0.1, 0.1]
      method(torch.tensor(score))
      torch.testing.assert_allclose(sample_gt_label.score, score)
  
      # Test invalid type
      with self.assertRaisesRegex(AssertionError, "be a torch.Tensor"):
          method(score)
  
      # Test invalid dims
      with self.assertRaisesRegex(AssertionError, "but got 2"):
          method(torch.tensor([score]))
  
      # Test invalid num_classes
      with self.assertRaisesRegex(
          AssertionError, r"length of value \(6\)"
      ):
          method(torch.tensor(score + [0.1]))
  
      # Test auto inter num_classes
      data_sample = ReIDDataSample()
      method = getattr(data_sample, "set_gt_score")
      method(torch.tensor(score))
      sample_gt_label = getattr(data_sample, "gt_label")
      self.assertEqual(sample_gt_label.num_classes, len(score))
  
file_path: mmdetection/tests/test_structures/test_reid_data_sample.py
imports: from unittest import TestCase
  import numpy
  import torch
  from mmengine.structures import LabelData
  from mmdet.structures import ReIDDataSample
label_desc: Use image node_id 3 for calling the TestReIDDataSample obj's underlying member method code with example usage: obj.test_set_gt_score() without return types