code: def gen_new_json(coco2017_train_path, json_data, coco2017_train_ids):
      coco = COCO(coco2017_train_path)
      new_json_data = {
          "info": json_data["info"],
          "licenses": json_data["licenses"],
          "categories": json_data["categories"],
          "images": [],
          "annotations": [],
      }
  
      for id in coco2017_train_ids:
          ann_ids = coco.getAnnIds(imgIds=[id])
          img_ann_info = coco.loadAnns(ann_ids)
          img_info = coco.loadImgs([id])[0]
  
          new_json_data["images"].append(img_info)
          new_json_data["annotations"].extend(img_ann_info)
      return new_json_data
  
imports: import argparse
  import json
  import os.path
  import mmengine
  from pycocotools.coco import COCO
label_desc: Use image node_id 2 for calling a global function with example usage: gen_new_json(coco2017_train_path, json_data, coco2017_train_ids) and returns: new_json_data