code: def main(_):
      if FLAGS.set not in SETS:
          raise ValueError("set must be in : {}".format(SETS))
      if FLAGS.year not in YEARS:
          raise ValueError("year must be in : {}".format(YEARS))
      if not FLAGS.output_path:
          raise ValueError("output_path cannot be empty.")
  
      data_dir = FLAGS.data_dir
      years = ["VOC2007", "VOC2012"]
      if FLAGS.year != "merged":
          years = [FLAGS.year]
  
      output_dir = os.path.dirname(FLAGS.output_path)
      if not tf.io.gfile.exists(output_dir):
          tf.io.gfile.makedirs(output_dir)
      logging.info("Writing to output directory: %s", output_dir)
  
      writers = [
          tf.io.TFRecordWriter(
              FLAGS.output_path
              + "-%05d-of-%05d.tfrecord" % (i, FLAGS.num_shards)
          )
          for i in range(FLAGS.num_shards)
      ]
  
      if FLAGS.label_map_json_path:
          with tf.io.gfile.GFile(FLAGS.label_map_json_path, "rb") as f:
              label_map_dict = json.load(f)
      else:
          label_map_dict = pascal_label_map_dict
  
      ann_json_dict = {
          "images": [],
          "type": "instances",
          "annotations": [],
          "categories": [],
      }
      for year in years:
          example_class = list(label_map_dict.keys())[1]
          examples_path = os.path.join(
              data_dir,
              year,
              "ImageSets",
              "Main",
              example_class + "_" + FLAGS.set + ".txt",
          )
          examples_list = tfrecord_util.read_examples_list(
              examples_path
          )
          annotations_dir = os.path.join(
              data_dir, year, FLAGS.annotations_dir
          )
  
          for class_name, class_id in label_map_dict.items():
              cls = {
                  "supercategory": "none",
                  "id": class_id,
                  "name": class_name,
              }
              ann_json_dict["categories"].append(cls)
  
          logging.info("Reading from PASCAL %s dataset.", year)
          for idx, example in enumerate(examples_list):
              if FLAGS.num_images and idx >= FLAGS.num_images:
                  break
              if idx % 100 == 0:
                  logging.info(
                      "On image %d of %d", idx, len(examples_list)
                  )
              path = os.path.join(annotations_dir, example + ".xml")
              with tf.io.gfile.GFile(path, "r") as fid:
                  xml_str = fid.read()
              xml = etree.fromstring(xml_str)
              data = tfrecord_util.recursive_parse_xml_to_dict(xml)[
                  "annotation"
              ]
  
              tf_example = dict_to_tf_example(
                  data,
                  FLAGS.data_dir,
                  label_map_dict,
                  FLAGS.ignore_difficult_instances,
                  ann_json_dict=ann_json_dict,
              )
              writers[idx % FLAGS.num_shards].write(
                  tf_example.SerializeToString()
              )
  
      for writer in writers:
          writer.close()
  
      json_file_path = os.path.join(
          os.path.dirname(FLAGS.output_path),
          "json_" + os.path.basename(FLAGS.output_path) + ".json",
      )
      with tf.io.gfile.GFile(json_file_path, "w") as f:
          json.dump(ann_json_dict, f)
  
file_path: DALI/docs/examples/use_cases/tensorflow/efficientdet/dataset/create_pascal_tfrecord.py
imports: import hashlib
  import io
  import json
  import os
  from absl import app
  from absl import flags
  from absl import logging
  from lxml import etree
  import PIL.Image
  import tensorflow
  from dataset import tfrecord_util
label_desc: Use image node_id 4 for calling a global function with example usage: main(_) without return types