def convert_to_rc(dataset, filename):
  """Convert dataset of ImageMetadata items to RC-formatted JSON file.

  Args:
    dataset: List of ImageMetadata.
    filename: Path to write to.
  """
  rc_data = collections.defaultdict(dict)
  for example in dataset:
    image_id = example.image_id
    for i, qid in enumerate(example.question_ids):
      question = example.questions[i]
      answers = example.answers[i]
      rc_data[image_id][qid] = dict(question=question, answers=answers)
  with tf.io.gfile.GFile(filename, "w") as f:
    json.dump(rc_data, f)
Convert dataset of ImageMetadata items to RC-formatted JSON file.

  Args:
    dataset: List of ImageMetadata.
    filename: Path to write to.
  
language/capwap/utils/io_utils.py