class_docstr: OCR test problem.
class_docstr_tok: ["OCR","test","problem","."]
code: def generator(self, data_dir, tmp_dir, is_training):
      # In this test problem, we assume that the data is in tmp_dir/ocr/ in
      # files names 0.png, 0.txt, 1.png, 1.txt and so on until num_examples.
      num_examples = 2
      ocr_dir = os.path.join(tmp_dir, "ocr/")
      tf.logging.info("Looking for OCR data in %s." % ocr_dir)
      for i in range(num_examples):
          image_filepath = os.path.join(ocr_dir, "%d.png" % i)
          text_filepath = os.path.join(ocr_dir, "%d.txt" % i)
          with tf.gfile.Open(text_filepath, "rb") as f:
              label = f.read()
          with tf.gfile.Open(image_filepath, "rb") as f:
              encoded_image_data = f.read()
          # In PNG files width and height are stored in these bytes.
          width, height = struct.unpack(
              ">ii", encoded_image_data[16:24]
          )
          yield {
              "image/encoded": [encoded_image_data],
              "image/format": ["png"],
              "image/class/label": label.strip(),
              "image/height": [height],
              "image/width": [width],
          }
  
file_path: tensor2tensor/tensor2tensor/data_generators/ocr.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import os
  import struct
  from tensor2tensor.data_generators import image_utils
  from tensor2tensor.data_generators import problem
  from tensor2tensor.utils import registry
  import tensorflow.compat.v1
label_desc: Use image node_id 7 for calling the OcrTest obj's underlying member method code with example usage: obj.generator(data_dir, tmp_dir, is_training) without return types