code: def _evaluate_predictions_on_coco(
      coco_gt,
      coco_results,
      iou_type,
      kpt_oks_sigmas=None,
      cocoeval_fn=COCOeval_opt,
      img_ids=None,
      max_dets_per_image=None,
  ):
      """
      Evaluate the coco results using COCOEval API.
      """
      assert len(coco_results) > 0
  
      if iou_type == "segm":
          coco_results = copy.deepcopy(coco_results)
          # When evaluating mask AP, if the results contain bbox, cocoapi will
          # use the box area as the area of the instance, instead of the mask area.
          # This leads to a different definition of small/medium/large.
          # We remove the bbox field to let mask AP use mask area.
          for c in coco_results:
              c.pop("bbox", None)
  
      coco_dt = coco_gt.loadRes(coco_results)
      coco_eval = cocoeval_fn(coco_gt, coco_dt, iou_type)
      # For COCO, the default max_dets_per_image is [1, 10, 100].
      if max_dets_per_image is None:
          max_dets_per_image = [1, 10, 100]  # Default from COCOEval
      else:
          assert (
              len(max_dets_per_image) >= 3
          ), "COCOeval requires maxDets (and max_dets_per_image) to have length at least 3"
          # In the case that user supplies a custom input for max_dets_per_image,
          # apply COCOevalMaxDets to evaluate AP with the custom input.
          if max_dets_per_image[2] != 100:
              coco_eval = COCOevalMaxDets(coco_gt, coco_dt, iou_type)
      if iou_type != "keypoints":
          coco_eval.params.maxDets = max_dets_per_image
  
      if img_ids is not None:
          coco_eval.params.imgIds = img_ids
  
      if iou_type == "keypoints":
          # Use the COCO default keypoint OKS sigmas unless overrides are specified
          if kpt_oks_sigmas:
              assert hasattr(
                  coco_eval.params, "kpt_oks_sigmas"
              ), "pycocotools is too old!"
              coco_eval.params.kpt_oks_sigmas = np.array(kpt_oks_sigmas)
          # COCOAPI requires every detection and every gt to have keypoints, so
          # we just take the first entry from both
          num_keypoints_dt = len(coco_results[0]["keypoints"]) // 3
          num_keypoints_gt = (
              len(next(iter(coco_gt.anns.values()))["keypoints"]) // 3
          )
          num_keypoints_oks = len(coco_eval.params.kpt_oks_sigmas)
          assert (
              num_keypoints_oks == num_keypoints_dt == num_keypoints_gt
          ), (
              f"[COCOEvaluator] Prediction contain {num_keypoints_dt} keypoints. "
              f"Ground truth contains {num_keypoints_gt} keypoints. "
              f"The length of cfg.TEST.KEYPOINT_OKS_SIGMAS is {num_keypoints_oks}. "
              "They have to agree with each other. For meaning of OKS, please refer to "
              "http://cocodataset.org/#keypoints-eval."
          )
  
      coco_eval.evaluate()
      coco_eval.accumulate()
      coco_eval.summarize()
  
      return coco_eval
  
imports: import contextlib
  import copy
  import io
  import itertools
  import json
  import logging
  import numpy
  import os
  import pickle
  from collections import OrderedDict
  import pycocotools.mask
  import torch
  from pycocotools.coco import COCO
  from pycocotools.cocoeval import COCOeval
  from tabulate import tabulate
  import detectron2.utils.comm
  from detectron2.config import CfgNode
  from detectron2.data import MetadataCatalog
  from detectron2.data.datasets.coco import convert_to_coco_json
  from detectron2.structures import Boxes, BoxMode, pairwise_iou
  from detectron2.utils.file_io import PathManager
  from detectron2.utils.logger import create_small_table
  from .evaluator import DatasetEvaluator
label_desc: Use image node_id 3 for calling a global function with example usage: _evaluate_predictions_on_coco(coco_gt, coco_results, iou_type, kpt_oks_sigmas, cocoeval_fn, img_ids, max_dets_per_image) and returns: coco_eval