code: def cocoapi_eval(
      jsonfile,
      style,
      coco_gt=None,
      anno_file=None,
      max_dets=(100, 300, 1000),
      classwise=False,
      sigmas=None,
      use_area=True,
  ):
      """
      Args:
          jsonfile (str): Evaluation json file, eg: bbox.json, mask.json.
          style (str): COCOeval style, can be `bbox` , `segm` , `proposal`, `keypoints` and `keypoints_crowd`.
          coco_gt (str): Whether to load COCOAPI through anno_file,
                   eg: coco_gt = COCO(anno_file)
          anno_file (str): COCO annotations file.
          max_dets (tuple): COCO evaluation maxDets.
          classwise (bool): Whether per-category AP and draw P-R Curve or not.
          sigmas (nparray): keypoint labelling sigmas.
          use_area (bool): If gt annotations (eg. CrowdPose, AIC)
                           do not have 'area', please set use_area=False.
      """
      assert coco_gt != None or anno_file != None
      if style == "keypoints_crowd":
          # please install xtcocotools==1.6
          from xtcocotools.coco import COCO
          from xtcocotools.cocoeval import COCOeval
      else:
          from pycocotools.coco import COCO
          from pycocotools.cocoeval import COCOeval
  
      if coco_gt == None:
          coco_gt = COCO(anno_file)
      logger.info("Start evaluate...")
      coco_dt = coco_gt.loadRes(jsonfile)
      if style == "proposal":
          coco_eval = COCOeval(coco_gt, coco_dt, "bbox")
          coco_eval.params.useCats = 0
          coco_eval.params.maxDets = list(max_dets)
      elif style == "keypoints_crowd":
          coco_eval = COCOeval(
              coco_gt, coco_dt, style, sigmas, use_area
          )
      else:
          coco_eval = COCOeval(coco_gt, coco_dt, style)
      coco_eval.evaluate()
      coco_eval.accumulate()
      coco_eval.summarize()
      if classwise:
          # Compute per-category AP and PR curve
          try:
              from terminaltables import AsciiTable
          except Exception as e:
              logger.error(
                  "terminaltables not found, plaese install terminaltables. "
                  "for example: `pip install terminaltables`."
              )
              raise e
          precisions = coco_eval.eval["precision"]
          cat_ids = coco_gt.getCatIds()
          # precision: (iou, recall, cls, area range, max dets)
          assert len(cat_ids) == precisions.shape[2]
          results_per_category = []
          for idx, catId in enumerate(cat_ids):
              # area range index 0: all area ranges
              # max dets index -1: typically 100 per image
              nm = coco_gt.loadCats(catId)[0]
              precision = precisions[:, :, idx, 0, -1]
              precision = precision[precision > -1]
              if precision.size:
                  ap = np.mean(precision)
              else:
                  ap = float("nan")
              results_per_category.append(
                  (str(nm["name"]), "{:0.3f}".format(float(ap)))
              )
              pr_array = precisions[0, :, idx, 0, 2]
              recall_array = np.arange(0.0, 1.01, 0.01)
              draw_pr_curve(
                  pr_array,
                  recall_array,
                  out_dir=style + "_pr_curve",
                  file_name="{}_precision_recall_curve.jpg".format(
                      nm["name"]
                  ),
              )
  
          num_columns = min(6, len(results_per_category) * 2)
          results_flatten = list(itertools.chain(*results_per_category))
          headers = ["category", "AP"] * (num_columns // 2)
          results_2d = itertools.zip_longest(
              *[
                  results_flatten[i::num_columns]
                  for i in range(num_columns)
              ]
          )
          table_data = [headers]
          table_data += [result for result in results_2d]
          table = AsciiTable(table_data)
          logger.info(
              "Per-category of {} AP: \n{}".format(style, table.table)
          )
          logger.info(
              "per-category PR curve has output to {} folder.".format(
                  style + "_pr_curve"
              )
          )
      # flush coco evaluation result
      sys.stdout.flush()
      return coco_eval.stats
  
file_path: PaddleDetection/ppdet/metrics/coco_utils.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import os
  import sys
  import numpy
  import itertools
  from ppdet.metrics.json_results import get_det_res, get_det_poly_res, get_seg_res, get_solov2_segm_res, get_keypoint_res, get_pose3d_res
  from ppdet.metrics.map_utils import draw_pr_curve
  from ppdet.utils.logger import setup_logger
label_desc: Use image node_id 2 for calling a global function with example usage: cocoapi_eval(jsonfile, style, coco_gt, anno_file, max_dets, classwise, sigmas, use_area) and returns: coco_eval