code: def test_batch_fixed_size_pad(self):
      # test pad_mask=False and pad_seg=False
      processor = DetDataPreprocessor(
          pad_mask=False,
          pad_seg=False,
          batch_augments=[
              dict(
                  type="BatchFixedSizePad",
                  size=(32, 32),
                  img_pad_value=0,
                  pad_mask=True,
                  mask_pad_value=0,
                  pad_seg=True,
                  seg_pad_value=0,
              )
          ],
      )
      self.assertTrue(
          isinstance(processor.batch_augments[0], BatchFixedSizePad)
      )
      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"]
      ]
      data = processor(packed_inputs, training=True)
      batch_inputs, batch_data_samples = (
          data["inputs"],
          data["data_samples"],
      )
      self.assertEqual(batch_inputs.shape[-2:], (32, 32))
      for (
          data_samples,
          expected_shape,
          mask_pad_sum,
          seg_pad_sum,
      ) in zip(
          batch_data_samples,
          [(32, 32), (32, 32)],
          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
          )
  
      # test pad_mask=True and pad_seg=True
      processor = DetDataPreprocessor(
          pad_mask=True,
          pad_seg=True,
          seg_pad_value=0,
          mask_pad_value=0,
          batch_augments=[
              dict(
                  type="BatchFixedSizePad",
                  size=(32, 32),
                  img_pad_value=0,
                  pad_mask=True,
                  mask_pad_value=0,
                  pad_seg=True,
                  seg_pad_value=0,
              )
          ],
      )
      self.assertTrue(
          isinstance(processor.batch_augments[0], BatchFixedSizePad)
      )
      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"]
      ]
      data = processor(packed_inputs, training=True)
      batch_inputs, batch_data_samples = (
          data["inputs"],
          data["data_samples"],
      )
      self.assertEqual(batch_inputs.shape[-2:], (32, 32))
      for (
          data_samples,
          expected_shape,
          mask_pad_sum,
          seg_pad_sum,
      ) in zip(
          batch_data_samples,
          [(32, 32), (32, 32)],
          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
          )
  
      # test negative pad/no pad
      processor = DetDataPreprocessor(
          pad_mask=True,
          pad_seg=True,
          seg_pad_value=0,
          mask_pad_value=0,
          batch_augments=[
              dict(
                  type="BatchFixedSizePad",
                  size=(5, 5),
                  img_pad_value=0,
                  pad_mask=True,
                  mask_pad_value=1,
                  pad_seg=True,
                  seg_pad_value=1,
              )
          ],
      )
      self.assertTrue(
          isinstance(processor.batch_augments[0], BatchFixedSizePad)
      )
      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"]
      ]
      data = processor(packed_inputs, training=True)
      batch_inputs, batch_data_samples = (
          data["inputs"],
          data["data_samples"],
      )
      self.assertEqual(batch_inputs.shape[-2:], (10, 24))
      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 5 for calling the TestDetDataPreprocessor obj's underlying member method code with example usage: obj.test_batch_fixed_size_pad() without return types