code: def exclude_coco(args):
      with open(args.coco2017_train, "r") as f:
          coco2017_train = json.load(f)
      coco2017_train_ids = [
          train["id"] for train in coco2017_train["images"]
      ]
      orig_len = len(coco2017_train_ids)
  
      with open(
          osp.join(args.mdetr_anno_dir, "finetune_refcoco_val.json"),
          "r",
      ) as f:
          refcoco_ann = json.load(f)
      refcoco_ids = [
          refcoco["original_id"] for refcoco in refcoco_ann["images"]
      ]
      coco2017_train_ids = diff_image_id(
          coco2017_train_ids, refcoco_ids
      )
  
      with open(
          osp.join(args.mdetr_anno_dir, "finetune_refcoco+_val.json"),
          "r",
      ) as f:
          refcoco_plus_ann = json.load(f)
      refcoco_plus_ids = [
          refcoco["original_id"]
          for refcoco in refcoco_plus_ann["images"]
      ]
      coco2017_train_ids = diff_image_id(
          coco2017_train_ids, refcoco_plus_ids
      )
  
      with open(
          osp.join(args.mdetr_anno_dir, "finetune_refcocog_val.json"),
          "r",
      ) as f:
          refcocog_ann = json.load(f)
      refcocog_ids = [
          refcoco["original_id"] for refcoco in refcocog_ann["images"]
      ]
      coco2017_train_ids = diff_image_id(
          coco2017_train_ids, refcocog_ids
      )
  
      with open(
          osp.join(args.mdetr_anno_dir, "finetune_grefcoco_val.json"),
          "r",
      ) as f:
          grefcoco_ann = json.load(f)
      grefcoco_ids = [
          refcoco["original_id"] for refcoco in grefcoco_ann["images"]
      ]
      coco2017_train_ids = diff_image_id(
          coco2017_train_ids, grefcoco_ids
      )
  
      coco2017_train_ids = list(coco2017_train_ids)
      print(
          "remove {} images from coco2017_train".format(
              orig_len - len(coco2017_train_ids)
          )
      )
  
      new_json_data = gen_new_json(
          args.coco2017_train, coco2017_train, coco2017_train_ids
      )
      if args.out_ann is None:
          out_ann = (
              osp.dirname(args.coco2017_train)
              + "/instances_train2017_norefval.json"
          )
          mmengine.dump(new_json_data, out_ann)
          print("save new json to {}".format(out_ann))
      else:
          mmengine.dump(new_json_data, args.out_ann)
          print("save new json to {}".format(args.out_ann))
  
imports: import argparse
  import json
  import os.path
  import mmengine
  from pycocotools.coco import COCO
label_desc: Use image node_id 3 for calling a global function with example usage: exclude_coco(args) without return types