code: def test_compare_both_same_time(tmpdir, backend):
      """Test that the class support evaluating both bbox and segm at the same time."""
      _skip_if_faster_coco_eval_missing(backend)
  
      with open(_DETECTION_BBOX) as f:
          boxes = json.load(f)
      with open(_DETECTION_SEGM) as f:
          segmentations = json.load(f)
      combined = [
          {**box, **seg} for box, seg in zip(boxes, segmentations)
      ]
      with open(f"{tmpdir}/combined.json", "w") as f:
          json.dump(combined, f)
      batched_preds, batched_target = MeanAveragePrecision.coco_to_tm(
          f"{tmpdir}/combined.json",
          _DETECTION_VAL,
          iou_type=["bbox", "segm"],
      )
      batched_preds = [
          batched_preds[10 * i : 10 * (i + 1)] for i in range(10)
      ]
      batched_target = [
          batched_target[10 * i : 10 * (i + 1)] for i in range(10)
      ]
  
      metric = MeanAveragePrecision(
          iou_type=["bbox", "segm"], box_format="xywh", backend=backend
      )
      for bp, bt in zip(batched_preds, batched_target):
          metric.update(bp, bt)
      res = metric.compute()
  
      res1 = _compare_against_coco_fn(
          [], [], iou_type="bbox", class_metrics=False
      )
      res2 = _compare_against_coco_fn(
          [], [], iou_type="segm", class_metrics=False
      )
  
      for k, v in res1.items():
          if k == "classes":
              continue
          assert f"bbox_{k}" in res
          assert torch.allclose(res[f"bbox_{k}"], v, atol=1e-2)
  
      for k, v in res2.items():
          if k == "classes":
              continue
          assert f"segm_{k}" in res
          assert torch.allclose(res[f"segm_{k}"], v, atol=1e-2)
  
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 4 for calling a global function with example usage: test_compare_both_same_time(tmpdir, backend) without return types