code: def test_filter_gt_instances():
      packed_inputs = demo_mm_inputs()["data_samples"]
      score_thr = 0.7
      with pytest.raises(AssertionError):
          filter_gt_instances(packed_inputs, score_thr=score_thr)
  
      # filter no instances by score
      for inputs in packed_inputs:
          inputs.gt_instances.scores = torch.ones_like(
              inputs.gt_instances.labels
          ).float()
      filtered_packed_inputs = filter_gt_instances(
          copy.deepcopy(packed_inputs), score_thr=score_thr
      )
      for filtered_inputs, inputs in zip(
          filtered_packed_inputs, packed_inputs
      ):
          assert len(filtered_inputs.gt_instances) == len(
              inputs.gt_instances
          )
  
      # filter all instances
      for inputs in packed_inputs:
          inputs.gt_instances.scores = torch.zeros_like(
              inputs.gt_instances.labels
          ).float()
      filtered_packed_inputs = filter_gt_instances(
          copy.deepcopy(packed_inputs), score_thr=score_thr
      )
      for filtered_inputs in filtered_packed_inputs:
          assert len(filtered_inputs.gt_instances) == 0
  
      packed_inputs = demo_mm_inputs()["data_samples"]
      # filter no instances by size
      wh_thr = (0, 0)
      filtered_packed_inputs = filter_gt_instances(
          copy.deepcopy(packed_inputs), wh_thr=wh_thr
      )
      for filtered_inputs, inputs in zip(
          filtered_packed_inputs, packed_inputs
      ):
          assert len(filtered_inputs.gt_instances) == len(
              inputs.gt_instances
          )
  
      # filter all instances by size
      for inputs in packed_inputs:
          img_shape = inputs.img_shape
          wh_thr = (
              max(wh_thr[0], img_shape[0]),
              max(wh_thr[1], img_shape[1]),
          )
      filtered_packed_inputs = filter_gt_instances(
          copy.deepcopy(packed_inputs), wh_thr=wh_thr
      )
      for filtered_inputs in filtered_packed_inputs:
          assert len(filtered_inputs.gt_instances) == 0
  
file_path: mmdetection/tests/test_models/test_utils/test_misc.py
imports: import copy
  import pytest
  import torch
  from mmengine.structures import InstanceData
  from mmdet.models.utils import empty_instances, filter_gt_instances, rename_loss_dict, reweight_loss_dict, unpack_gt_instances
  from mmdet.testing import demo_mm_inputs
label_desc: Use image node_id 3 for calling a global function with example usage: test_filter_gt_instances() without return types