code: def coco2odvg(args):
      coco = COCO(args.input)
      cats = coco.loadCats(coco.getCatIds())
      nms = {cat["id"]: cat["name"] for cat in cats}
      metas = []
      if args.output is None:
          out_path = args.input[:-5] + "_od.json"
      else:
          out_path = args.output
  
      if args.dataset == "coco":
          key_list = key_list_coco
          val_list = val_list_coco
          dump_coco_label_map(args)
      elif args.dataset == "o365v1":
          key_list = key_list_o365
          val_list = val_list_o365
          dump_o365v1_label_map(args)
      elif args.dataset == "o365v2":
          key_list = key_list_o365
          val_list = val_list_o365
          dump_o365v2_label_map(args)
      elif args.dataset == "v3det":
          key_list = key_list_v3det
          val_list = val_list_v3det
          dump_v3det_label_map(args)
  
      for img_id, img_info in tqdm(coco.imgs.items()):
          # missing images
          if args.dataset == "o365v2" and img_id in [
              908726,
              320532,
              320534,
          ]:
              print(img_info["file_name"])
              continue
          if args.dataset == "o365v1" and img_id in [6, 19, 23]:
              print(img_info["file_name"])
              continue
  
          if args.dataset == "o365v2":
              file_name = img_info["file_name"]
              if file_name.startswith("images/v2/"):
                  file_name = file_name.replace("images/v2/", "")
              elif file_name.startswith("images/v1/"):
                  file_name = file_name.replace("images/v1/", "")
              img_info["file_name"] = file_name
  
          ann_ids = coco.getAnnIds(imgIds=img_id)
          instance_list = []
          for ann_id in ann_ids:
              ann = coco.anns[ann_id]
  
              if ann.get("ignore", False):
                  continue
              x1, y1, w, h = ann["bbox"]
              inter_w = max(
                  0, min(x1 + w, img_info["width"]) - max(x1, 0)
              )
              inter_h = max(
                  0, min(y1 + h, img_info["height"]) - max(y1, 0)
              )
              if inter_w * inter_h == 0:
                  continue
              if ann["area"] <= 0 or w < 1 or h < 1:
                  continue
  
              if ann.get("iscrowd", False):
                  continue
  
              bbox_xyxy = [x1, y1, x1 + w, y1 + h]
              label = ann["category_id"]
              category = nms[label]
              ind = val_list.index(label)
              label_trans = key_list[ind]
              instance_list.append(
                  {
                      "bbox": bbox_xyxy,
                      "label": label_trans,
                      "category": category,
                  }
              )
          metas.append(
              {
                  "filename": img_info["file_name"],
                  "height": img_info["height"],
                  "width": img_info["width"],
                  "detection": {"instances": instance_list},
              }
          )
  
      with jsonlines.open(out_path, mode="w") as writer:
          writer.write_all(metas)
  
      print("save to {}".format(out_path))
  
file_path: mmdetection/tools/dataset_converters/coco2odvg.py
imports: import argparse
  import json
  import os.path
  import jsonlines
  from pycocotools.coco import COCO
  from tqdm import tqdm
label_desc: Use image node_id 5 for calling a global function with example usage: coco2odvg(args) without return types