class_docstr: VQA V2, raw images, 10k question vocab, 3k answer label.
class_docstr_tok: ["VQA","V2",",","raw","images",",","10k","question","vocab",",","3k","answer","label","."]
docstr: VQA v2 generator using raw images.
code: def vqa_v2_generator(self, data_dir, tmp_dir, datasets):
      """VQA v2 generator using raw images."""
      _get_vqa_v2_annotations(tmp_dir, self._VQA_V2_ANNOTATION_URL)
      _get_vqa_v2_image_raw_dataset(
          tmp_dir, self._MSCOCO_ROOT_URL, self._MSCOCO_IMAGE_URLS
      )
      vocab_path = os.path.join(data_dir, self.vocab_filename)
      if not tf.gfile.Exists(vocab_path):
          vocab_tmp_path = os.path.join(tmp_dir, self.vocab_filename)
          tf.gfile.Copy(vocab_tmp_path, vocab_path)
          with tf.gfile.GFile(vocab_path, mode="r") as f:
              vocab_data = "<pad>\n<EOS>\n" + f.read() + "UNK\n"
          with tf.gfile.GFile(vocab_path, mode="w") as f:
              f.write(vocab_data)
      label_path = os.path.join(data_dir, self.label_filename)
      if not tf.gfile.Exists(label_path):
          label_tmp_path = os.path.join(tmp_dir, self.label_filename)
          tf.gfile.Copy(label_tmp_path, label_path)
  
      vocab_encoder = text_encoder.TokenTextEncoder(
          vocab_path, replace_oov="UNK"
      )
      label_encoder = text_encoder.ClassLabelEncoder(
          class_labels_fname=label_path
      )
  
      prefix_annotation = []
      for prefix, annotation_file in datasets:
          annotation_path = os.path.join(tmp_dir, annotation_file)
          with tf.gfile.Open(annotation_path) as f:
              annotation_json = json.loads(f.read())
          prefix_annotation += [
              (prefix, anno) for anno in annotation_json
          ]
      random.shuffle(prefix_annotation)
      annotation_count = len(prefix_annotation)
      tf.logging.info(
          "Processing %d annotations for vqa v2" % (annotation_count)
      )
  
      for prefix, anno in prefix_annotation:
          image_id = anno["image_id"]
          question = vocab_encoder.encode(anno["question"])
          answer = [label_encoder.encode(ans) for ans in anno["answer"]]
          answer = answer if answer else [0]  # 0 indicates padding
          image_filename = (
              "COCO_" + prefix + "_" + str(image_id).zfill(12) + ".jpg"
          )
          image_filepath = os.path.join(tmp_dir, prefix, image_filename)
          with tf.gfile.Open(image_filepath, "r") as f:
              encoded_image_data = f.read()
              yield {
                  "image/encoded": [encoded_image_data],
                  "image/format": ["jpeg"],
                  "image/image_id": [image_id],
                  "image/question_id": [anno["question_id"]],
                  "image/question": question,
                  "image/answer": answer,
              }
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import base64
  import csv
  import json
  import os
  import random
  import sys
  import tarfile
  import zipfile
  import numpy
  from tensor2tensor.data_generators import generator_utils
  from tensor2tensor.data_generators import image_utils
  from tensor2tensor.data_generators import problem
  from tensor2tensor.data_generators import text_encoder
  from tensor2tensor.data_generators import vqa_utils
  from tensor2tensor.layers import modalities
  from tensor2tensor.utils import contrib
  from tensor2tensor.utils import metrics
  from tensor2tensor.utils import registry
  import tensorflow.compat.v1
label_desc: Use image node_id 12 for calling the ImageVqav2Tokens10kLabels3k obj's underlying member method code with example usage: obj.vqa_v2_generator(data_dir, tmp_dir, datasets) without return types