code: def _create_tf_record_from_coco_annotations(
      image_info_file,
      image_dir,
      output_path,
      num_shards,
      object_annotations_file=None,
      caption_annotations_file=None,
  ):
      """Loads COCO annotation json files and converts to tf.Record format.
  
      Args:
        image_info_file: JSON file containing image info. The number of tf.Examples
          in the output tf Record files is exactly equal to the number of image info
          entries in this file. This can be any of train/val/test annotation json
          files Eg. 'image_info_test-dev2017.json',
          'instance_annotations_train2017.json',
          'caption_annotations_train2017.json', etc.
        image_dir: Directory containing the image files.
        output_path: Path to output tf.Record file.
        num_shards: Number of output files to create.
        object_annotations_file: JSON file containing bounding box annotations.
        caption_annotations_file: JSON file containing caption annotations.
      """
  
      logging.info("writing to output path: %s", output_path)
      writers = [
          tf.io.TFRecordWriter(
              output_path + "-%05d-of-%05d.tfrecord" % (i, num_shards)
          )
          for i in range(num_shards)
      ]
      images = _load_images_info(image_info_file)
  
      img_to_obj_annotation = None
      img_to_caption_annotation = None
      category_index = None
      if object_annotations_file:
          (
              img_to_obj_annotation,
              category_index,
          ) = _load_object_annotations(object_annotations_file)
      if caption_annotations_file:
          img_to_caption_annotation = _load_caption_annotations(
              caption_annotations_file
          )
  
      def _get_object_annotation(image_id):
          if img_to_obj_annotation:
              return img_to_obj_annotation[image_id]
          else:
              return None
  
      def _get_caption_annotation(image_id):
          if img_to_caption_annotation:
              return img_to_caption_annotation[image_id]
          else:
              return None
  
      pool = multiprocessing.Pool(FLAGS.num_threads)
      total_num_annotations_skipped = 0
      for idx, (_, tf_example, num_annotations_skipped) in enumerate(
          pool.imap(
              _pool_create_tf_example,
              [
                  (
                      image,
                      image_dir,
                      _get_object_annotation(image["id"]),
                      category_index,
                      _get_caption_annotation(image["id"]),
                  )
                  for image in images
              ],
          )
      ):
          if idx % 100 == 0:
              logging.info("On image %d of %d", idx, len(images))
  
          total_num_annotations_skipped += num_annotations_skipped
          writers[idx % num_shards].write(
              tf_example.SerializeToString()
          )
  
      pool.close()
      pool.join()
  
      for writer in writers:
          writer.close()
  
      logging.info(
          "Finished writing, skipped %d annotations.",
          total_num_annotations_skipped,
      )
  
imports: import collections
  import hashlib
  import io
  import json
  import multiprocessing
  import os
  from absl import app
  from absl import flags
  from absl import logging
  import numpy
  import PIL.Image
  import tensorflow
  import tfrecord_util
  import label_map_util
label_desc: Use image node_id 6 for calling a global function with example usage: _create_tf_record_from_coco_annotations(image_info_file, image_dir, output_path, num_shards, object_annotations_file, caption_annotations_file) and returns: img_to_obj_annotation, None, img_to_caption_annotation, None