code: def _evaluate_predictions_on_coco(
      coco_gt, coco_results, iou_type, kpt_oks_sigmas=None
  ):
      """
      Evaluate the coco results using COCOEval API.
      """
      try_import_pycocotools()
      from pycocotools.cocoeval import COCOeval
  
      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(coco_gt, coco_dt, iou_type)
  
      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.CONFIG.VAL.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 os
  import pickle
  from collections import OrderedDict
  import numpy
  import torch
  import pandas
  from ..None import comm
  from ...data.registry.catalog import MetadataCatalog
  from ...data.registry.mscoco import convert_to_coco_json
  from ...data.structures import Boxes, BoxMode, pairwise_iou
  from ...data.detection.detection_utils import try_import_pycocotools
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) and returns: coco_eval