code: def create_instances(predictions, image_size):
      ret = Instances(image_size)
  
      score = np.asarray([x["score"] for x in predictions])
      chosen = (score > args.conf_threshold).nonzero()[0]
      score = score[chosen]
      bbox = np.asarray(
          [predictions[i]["bbox"] for i in chosen]
      ).reshape(-1, 4)
      bbox = BoxMode.convert(bbox, BoxMode.XYWH_ABS, BoxMode.XYXY_ABS)
  
      labels = np.asarray(
          [
              dataset_id_map(predictions[i]["category_id"])
              for i in chosen
          ]
      )
  
      ret.scores = score
      ret.pred_boxes = Boxes(bbox)
      ret.pred_classes = labels
  
      try:
          ret.pred_masks = [
              predictions[i]["segmentation"] for i in chosen
          ]
      except KeyError:
          pass
      return ret
  
file_path: detectron2/tools/visualize_json_results.py
imports: import argparse
  import json
  import numpy
  import os
  from collections import defaultdict
  import cv2
  import tqdm
  from detectron2.data import DatasetCatalog, MetadataCatalog
  from detectron2.structures import Boxes, BoxMode, Instances
  from detectron2.utils.file_io import PathManager
  from detectron2.utils.logger import setup_logger
  from detectron2.utils.visualizer import Visualizer
label_desc: Use image node_id 1 for calling a global function with example usage: create_instances(predictions, image_size) and returns: ret