code: def test_instance_segmentation_output_transform():
      sample = {
          DataKeys.INPUT: torch.rand(3, 224, 224),
          DataKeys.PREDS: {
              "bboxes": [
                  {"xmin": 10, "ymin": 10, "width": 15, "height": 15},
                  {"xmin": 30, "ymin": 30, "width": 40, "height": 40},
              ],
              "labels": [0, 1],
              "masks": [
                  np.random.randint(
                      2, size=(1, 128, 128), dtype=np.uint8
                  ),
                  np.random.randint(
                      2, size=(1, 128, 128), dtype=np.uint8
                  ),
              ],
              "scores": [0.5, 0.5],
          },
          DataKeys.METADATA: {"size": (224, 224)},
      }
  
      output_transform_cls = InstanceSegmentationOutputTransform()
      data = output_transform_cls.per_sample_transform(sample)
  
      assert data["masks"][0].size() == (1, 224, 224)
      assert data["masks"][1].size() == (1, 224, 224)
  
file_path: lightning-flash/tests/image/instance_segm/test_data.py
imports: import numpy
  import pytest
  import torch
  from flash.core.data.io.input import DataKeys
  from flash.core.utilities.imports import _TOPIC_IMAGE_AVAILABLE
  from flash.image.instance_segmentation import InstanceSegmentationData
  from flash.image.instance_segmentation.data import InstanceSegmentationOutputTransform
  from tests.image.detection.test_data import _create_synth_files_dataset, _create_synth_folders_dataset
label_desc: Use image node_id 3 for calling a global function with example usage: test_instance_segmentation_output_transform() without return types