code: def convert_xmls_to_cocojson(
      annotation_paths: List[str],
      label2id: Dict[str, int],
      output_jsonpath: str,
      extract_num_from_imgid: bool = True,
      root_dir: str = "./",
  ):
      output_json_dict = {
          "images": [],
          "type": "instances",
          "annotations": [],
          "categories": [],
      }
      bnd_id = 1  # START_BOUNDING_BOX_ID, TODO input as args ?
      print("Start converting !")
      for a_path in tqdm(annotation_paths):
          # Read annotation xml
          try:
              ann_tree = ET.parse(a_path)
          except:
              ann_tree = ET.parse(os.path.join(root_dir, a_path))
          ann_root = ann_tree.getroot()
  
          img_info = get_image_info(
              annotation_root=ann_root,
              extract_num_from_imgid=extract_num_from_imgid,
          )
          img_id = img_info["id"]
  
          valid_image = False  # remove image without bounding box to speed up mAP calculation
          for obj in ann_root.findall("object"):
              ann = get_coco_annotation_from_obj(
                  obj=obj, label2id=label2id
              )
              if ann:
                  ann.update({"image_id": img_id, "id": bnd_id})
                  output_json_dict["annotations"].append(ann)
                  bnd_id = bnd_id + 1
                  valid_image = True
  
          if valid_image:
              output_json_dict["images"].append(img_info)
  
      for label, label_id in label2id.items():
          category_info = {
              "supercategory": "none",
              "id": label_id,
              "name": label,
          }
          output_json_dict["categories"].append(category_info)
  
      with open(output_jsonpath, "w") as f:
          output_json = json.dumps(output_json_dict)
          f.write(output_json)
          print(
              f"The COCO format annotation is saved to {output_jsonpath}"
          )
  
file_path: autogluon/multimodal/src/autogluon/multimodal/cli/voc2coco.py
imports: import argparse
  import json
  import os
  import random
  import re
  import subprocess
  from typing import Dict, List
  import defusedxml.ElementTree
  from tqdm import tqdm
  from autogluon.multimodal.utils.object_detection import dump_voc_classes, dump_voc_xml_files, process_voc_annotations
label_desc: Use image node_id 5 for calling a global function with example usage: convert_xmls_to_cocojson(annotation_paths, label2id, output_jsonpath, extract_num_from_imgid, root_dir) without return types