code: def main():
      parser = argparse.ArgumentParser(
          description="This script support converting voc format xmls to coco format json"
      )
      parser.add_argument(
          "--root_dir",
          type=str,
          default=None,
          help="path to VOC format dataset root",
      )
      parser.add_argument(
          "--train_ratio",
          type=float,
          default=None,
          help="training set ratio",
      )
      parser.add_argument(
          "--val_ratio",
          type=float,
          default=None,
          help="validation set ratio",
      )
      parser.add_argument(
          "--ext",
          type=str,
          default=".jpg",
          help="default extension for image file",
      )
      parser.add_argument(
          "--min_area",
          type=int,
          default=4,
          help="min area for a valid bounding box",
      )
      parser.add_argument(
          "--not_extract_num_from_imgid",
          action="store_true",
          help="Extract image number from the image filename",
      )
      args = parser.parse_args()
  
      annpaths_list_path = None
      DEFAULT_EXT = args.ext
      MIN_AREA = args.min_area
      assert DEFAULT_EXT in [".jpg", ".png"]
  
      if not args.root_dir:
          raise ValueError(
              "Must specify the root of the VOC format dataset."
          )
      if args.train_ratio is not None:
          assert args.train_ratio >= 0
          assert args.val_ratio >= 0
          assert args.train_ratio + args.val_ratio <= 1
          annpaths_list_path = os.path.join(
              args.root_dir, "pathlist.txt"
          )
          ## generate pathlist.txt containing all xml file paths
          dump_voc_xml_files(
              voc_annotation_path=os.path.join(
                  args.root_dir, "Annotations"
              ),
              voc_annotation_xml_output_path=annpaths_list_path,
          )
  
          assert os.path.exists(
              annpaths_list_path
          ), "FatalError: pathlist.txt does not exist!"
  
      labels_path = os.path.join(args.root_dir, "labels.txt")
      ## generate labels.txt containing all unique class names
      dump_voc_classes(
          voc_annotation_path=os.path.join(
              args.root_dir, "Annotations"
          ),
          voc_class_names_output_path=labels_path,
      )
  
      assert os.path.exists(
          labels_path
      ), "FatalError: labels.txt does not exist!"
  
      output_path_fmt = os.path.join(
          args.root_dir, "Annotations", "%s_cocoformat.json"
      )
  
      label2id = get_label2id(labels_path=labels_path)
      ann_paths = get_annpaths(
          root_dir=args.root_dir,
          annpaths_list_path=annpaths_list_path,
          train_ratio=args.train_ratio,
          val_ratio=args.val_ratio,
      )
      for mode in ann_paths.keys():
          convert_xmls_to_cocojson(
              annotation_paths=ann_paths[mode],
              label2id=label2id,
              output_jsonpath=output_path_fmt % mode,
              extract_num_from_imgid=(
                  not args.not_extract_num_from_imgid
              ),
              root_dir=args.root_dir,
          )
  
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 6 for calling a global function with example usage: main() without return types