code: def eval_ng(
      gt_data,
      gt_ng_ids,
      preds_data,
      image_root="",
      instance_level=True,
      iou_theshold=0.1,
  ):
      ok_image_in_ng_num, ok_instance_in_ng_num, ng_instance_num = (
          0,
          0,
          0,
      )
      class_list = gt_data.getCatIds()
      clsid_to_name = gt_data.cats
      class_name = [clsid_to_name[i]["name"] for i in class_list]
      ng_class_num = defaultdict(int)
      ok_in_ng_class_num = defaultdict(int)
      escape_info_image = []
      escape_info_instance = defaultdict(list)
      for ng_id in gt_ng_ids:
          im_name = gt_data.loadImgs(ng_id)[0]["file_name"]
          preds_info = preds_data[osp.join(image_root, im_name)]
          if not preds_info["isNG"]:
              ok_image_in_ng_num += 1
              escape_info_image.append(ng_id)
          if instance_level:
              gt_anno_id = gt_data.getAnnIds(
                  imgIds=ng_id, iscrowd=False
              )
              gt_annos = gt_data.loadAnns(gt_anno_id)
              if len(gt_annos) == 0:
                  continue
              ng_instance_num += len(gt_annos)
              if not preds_info["isNG"]:
                  ok_instance_in_ng_num += len(gt_annos)
                  for gt in gt_annos:
                      ok_in_ng_class_num[gt["category_id"]] += 1
                      ng_class_num[gt["category_id"]] += 1
                      escape_info_instance[gt["category_id"]].append(
                          (ng_id, gt["id"])
                      )
              else:
                  pred_bbox = []
                  for pred in preds_info["pred"]:
                      if pred["isNG"]:
                          pred_bbox.append(pred["bbox"])
  
                  for gt in gt_annos:
                      ng_class_num[gt["category_id"]] += 1
                      max_iou = max(
                          iou_one_to_multiple(gt["bbox"], pred_bbox)
                      )
                      if max_iou < iou_theshold:
                          ok_instance_in_ng_num += 1
                          ok_in_ng_class_num[gt["category_id"]] += 1
                          escape_info_instance[
                              gt["category_id"]
                          ].append((ng_id, gt["id"]))
  
      ng_num = len(gt_ng_ids)
      column_names = ["Image Level", "Total", "NG", "OK", "Escape"]
      table = pt.PrettyTable(column_names)
      table.add_row(
          [
              "Lucky Result",
              ng_num,
              ng_num - ok_image_in_ng_num,
              ok_image_in_ng_num,
              "{:.2f}%".format(ok_image_in_ng_num / ng_num * 100)
              if ng_num > 0
              else 0,
          ]
      )
      logger.info(
          "Result of Image-Level NG NG Evaluation:\n" + str(table)
      )
  
      if instance_level:
          ng_class_num = [ng_class_num[cat] for cat in class_list]
          ok_in_ng_class_num = [
              ok_in_ng_class_num[cat] for cat in class_list
          ]
          column_names = ["NG", "ALL", *class_name]
          table = pt.PrettyTable(column_names)
          table.add_row(
              ["Total", ng_instance_num, *[x for x in ng_class_num]]
          )
          table.add_row(
              [
                  "NG",
                  ng_instance_num - ok_instance_in_ng_num,
                  *[
                      ng_class_num[i] - ok_in_ng_class_num[i]
                      for i in range(len(ng_class_num))
                  ],
              ]
          )
          table.add_row(
              [
                  "OK",
                  ok_instance_in_ng_num,
                  *[x for x in ok_in_ng_class_num],
              ]
          )
          table.add_row(
              [
                  " Escape ",
                  "{:.2f}%".format(
                      ok_instance_in_ng_num / ng_instance_num * 100
                  )
                  if ng_instance_num > 0
                  else 0,
                  *[
                      "{:.2f}%".format(
                          ok_in_ng_class_num[i] / ng_class_num[i] * 100
                      )
                      for i in range(len(ng_class_num))
                  ],
              ]
          )
          logger.info(
              "Result of Instance-Level NG Evaluation:\n" + str(table)
          )
  
      return escape_info_image, escape_info_instance
  
imports: import argparse
  import json
  import os
  import os.path
  import sys
  from collections import defaultdict
  import prettytable
  from pycocotools.coco import COCO
  from qinspector.cvlib.configs import ConfigParser
  from qinspector.ops.postprocess import PostProcess
  from qinspector.utils.logger import setup_logger
  from qinspector.utils.bbox_utils import iou_one_to_multiple
  from qinspector.utils.visualizer import show_result, draw_bboxes
label_desc: Use image node_id 4 for calling a global function with example usage: eval_ng(gt_data, gt_ng_ids, preds_data, image_root, instance_level, iou_theshold) and returns: escape_info_image,  escape_info_instance