code: def gen(self, batch_size):
      dataset = self.dataset.batch(batch_size)
      iterator = tf.compat.v1.data.make_one_shot_iterator(dataset)
  
      images, labels, comments = iterator.get_next()
      with tf.compat.v1.Session(
          config=tf.compat.v1.ConfigProto(allow_soft_placement=True)
      ) as sess:
          while True:
              try:
                  raw_images, raw_labels, raw_comments = sess.run(
                      [images, labels, comments]
                  )
                  for img, lex, comment in zip(
                      raw_images, raw_labels, raw_comments
                  ):
                      if self.max_width and (
                          Image.open(IO(img)).size[0] <= self.max_width
                      ):
                          word = self.convert_lex(lex)
  
                          bucket_size = self.bucket_data.append(
                              img, word, lex, comment
                          )
                          if bucket_size >= batch_size:
                              bucket = self.bucket_data.flush_out(
                                  self.bucket_specs, go_shift=1
                              )
                              yield bucket
  
              except tf.errors.OutOfRangeError:
                  break
  
      self.clear()
  
file_path: attention-ocr/aocr/util/data_gen.py
imports: from __future__ import absolute_import
  import sys
  import numpy
  import tensorflow
  from PIL import Image
  from six import BytesIO
  from .bucketdata import BucketData
label_desc: Use image node_id 4 for calling the DataGen obj's underlying member method code with example usage: obj.gen(batch_size) without return types