code: def test_forward(self):
      processor = DetDataPreprocessor(mean=[0, 0, 0], std=[1, 1, 1])
  
      data = {
          "inputs": [torch.randint(0, 256, (3, 11, 10))],
          "data_samples": [DetDataSample()],
      }
      out_data = processor(data)
      batch_inputs, batch_data_samples = (
          out_data["inputs"],
          out_data["data_samples"],
      )
  
      self.assertEqual(batch_inputs.shape, (1, 3, 11, 10))
      self.assertEqual(len(batch_data_samples), 1)
  
      # test channel_conversion
      processor = DetDataPreprocessor(
          mean=[0.0, 0.0, 0.0], std=[1.0, 1.0, 1.0], bgr_to_rgb=True
      )
      out_data = processor(data)
      batch_inputs, batch_data_samples = (
          out_data["inputs"],
          out_data["data_samples"],
      )
      self.assertEqual(batch_inputs.shape, (1, 3, 11, 10))
      self.assertEqual(len(batch_data_samples), 1)
  
      # test padding
      data = {
          "inputs": [
              torch.randint(0, 256, (3, 10, 11)),
              torch.randint(0, 256, (3, 9, 14)),
          ]
      }
      processor = DetDataPreprocessor(
          mean=[0.0, 0.0, 0.0], std=[1.0, 1.0, 1.0], bgr_to_rgb=True
      )
      out_data = processor(data)
      batch_inputs, batch_data_samples = (
          out_data["inputs"],
          out_data["data_samples"],
      )
      self.assertEqual(batch_inputs.shape, (2, 3, 10, 14))
      self.assertIsNone(batch_data_samples)
  
      # test pad_size_divisor
      data = {
          "inputs": [
              torch.randint(0, 256, (3, 10, 11)),
              torch.randint(0, 256, (3, 9, 24)),
          ],
          "data_samples": [DetDataSample()] * 2,
      }
      processor = DetDataPreprocessor(
          mean=[0.0, 0.0, 0.0], std=[1.0, 1.0, 1.0], pad_size_divisor=5
      )
      out_data = processor(data)
      batch_inputs, batch_data_samples = (
          out_data["inputs"],
          out_data["data_samples"],
      )
      self.assertEqual(batch_inputs.shape, (2, 3, 10, 25))
      self.assertEqual(len(batch_data_samples), 2)
      for data_samples, expected_shape in zip(
          batch_data_samples, [(10, 15), (10, 25)]
      ):
          self.assertEqual(data_samples.pad_shape, expected_shape)
  
      # test pad_mask=True and pad_seg=True
      processor = DetDataPreprocessor(
          pad_mask=True, mask_pad_value=0, pad_seg=True, seg_pad_value=0
      )
      packed_inputs = demo_mm_inputs(
          2,
          [[3, 10, 11], [3, 9, 24]],
          with_mask=True,
          with_semantic=True,
          use_box_type=True,
      )
      packed_inputs["data_samples"][
          0
      ].gt_sem_seg.sem_seg = torch.randint(0, 256, (1, 10, 11))
      packed_inputs["data_samples"][
          1
      ].gt_sem_seg.sem_seg = torch.randint(0, 256, (1, 9, 24))
      mask_pad_sums = [
          x.gt_instances.masks.masks.sum()
          for x in packed_inputs["data_samples"]
      ]
      seg_pad_sums = [
          x.gt_sem_seg.sem_seg.sum()
          for x in packed_inputs["data_samples"]
      ]
      batch_data_samples = processor(packed_inputs, training=True)[
          "data_samples"
      ]
      for (
          data_samples,
          expected_shape,
          mask_pad_sum,
          seg_pad_sum,
      ) in zip(
          batch_data_samples,
          [(10, 24), (10, 24)],
          mask_pad_sums,
          seg_pad_sums,
      ):
          self.assertEqual(
              data_samples.gt_instances.masks.masks.shape[-2:],
              expected_shape,
          )
          self.assertEqual(
              data_samples.gt_sem_seg.sem_seg.shape[-2:], expected_shape
          )
          self.assertEqual(
              data_samples.gt_instances.masks.masks.sum(), mask_pad_sum
          )
          self.assertEqual(
              data_samples.gt_sem_seg.sem_seg.sum(), seg_pad_sum
          )
  
file_path: mmdetection/tests/test_models/test_data_preprocessors/test_data_preprocessor.py
imports: from unittest import TestCase
  import torch
  from mmengine.logging import MessageHub
  from mmdet.models.data_preprocessors import BatchFixedSizePad, BatchSyncRandomResize, DetDataPreprocessor, MultiBranchDataPreprocessor
  from mmdet.structures import DetDataSample
  from mmdet.testing import demo_mm_inputs
label_desc: Use image node_id 3 for calling the TestDetDataPreprocessor obj's underlying member method code with example usage: obj.test_forward() without return types