def load_captions(captions_file, vocab):
  """Loads image ids and processes the captions.

  Args:
    captions_file: JSON file containing caption annotations.
    vocab: A text_utils.Vocab instance.

  Returns:
    captions: Dictionary of image_id --> caption RCInputs.
  """
  tf.logging.info("Loading captions from %s", captions_file)
  with tf.io.gfile.GFile(captions_file, "r") as f:
    caption_data = json.load(f)

  image_to_captions = collections.defaultdict(list)
  for annotation in caption_data["annotations"]:
    image_id = annotation["image_id"]
    caption = vocab.tokenize(annotation["caption"])
    caption = caption[:FLAGS.max_length - FLAGS.query_length - 3]
    question = [vocab.PAD for _ in range(FLAGS.query_length)]
    inputs = [vocab.CLS] + question + [vocab.SEP] + caption + [vocab.SEP]
    input_ids = [vocab.t2i(t) for t in inputs]
    input_mask = [1 for _ in range(len(inputs))]
    segment_ids = ([0 for _ in range(len(question) + 2)] +
                   [1 for _ in range(len(caption) + 1)])
    for _ in range(FLAGS.max_length - len(input_ids)):
      input_ids.append(0)
      input_mask.append(0)
      segment_ids.append(0)
    image_to_captions[image_id].append((input_ids, input_mask, segment_ids))
  return image_to_captions
Loads image ids and processes the captions.

  Args:
    captions_file: JSON file containing caption annotations.
    vocab: A text_utils.Vocab instance.

  Returns:
    captions: Dictionary of image_id --> caption RCInputs.
  
language/capwap/preprocessing/coco_synthetic_qa.py