code: def _generate_random_segm_input(
      device,
      batch_size=2,
      num_preds_size=10,
      num_gt_size=10,
      random_size=True,
  ):
      """Generate random inputs for mAP when iou_type=segm."""
      preds = []
      targets = []
      for _ in range(batch_size):
          result = {}
          num_preds = (
              torch.randint(0, num_preds_size, (1,)).item()
              if random_size
              else num_preds_size
          )
          result["scores"] = torch.rand((num_preds,), device=device)
          result["labels"] = torch.randint(
              0, 10, (num_preds,), device=device
          )
          result["masks"] = torch.randint(
              0, 2, (num_preds, 10, 10), device=device
          ).bool()
          preds.append(result)
          gt = {}
          num_gt = (
              torch.randint(0, num_gt_size, (1,)).item()
              if random_size
              else num_gt_size
          )
          gt["labels"] = torch.randint(0, 10, (num_gt,), device=device)
          gt["masks"] = torch.randint(
              0, 2, (num_gt, 10, 10), device=device
          ).bool()
          targets.append(gt)
      return preds, targets
  
imports: import contextlib
  import io
  import json
  from copy import deepcopy
  from functools import partial
  from itertools import product
  import numpy
  import pytest
  import torch
  from lightning_utilities import apply_to_collection
  from pycocotools.coco import COCO
  from pycocotools.cocoeval import COCOeval
  from torch import IntTensor, Tensor
  from torchmetrics.detection.mean_ap import MeanAveragePrecision
  from torchmetrics.utilities.imports import _FASTER_COCO_EVAL_AVAILABLE, _PYCOCOTOOLS_AVAILABLE, _TORCHVISION_GREATER_EQUAL_0_8
  from unittests.detection import _DETECTION_BBOX, _DETECTION_SEGM, _DETECTION_VAL
  from unittests.helpers.testers import MetricTester
label_desc: Use image node_id 5 for calling a global function with example usage: _generate_random_segm_input(device, batch_size, num_preds_size, num_gt_size, random_size) and returns: preds,  targets