class_docstr: A text detector using the CRNN architecture.
  
  Args:
      alphabet: The alphabet the model should recognize.
      build_params: A dictionary of build parameters for the model.
          See `keras_ocr.recognition.build_model` for details.
      weights: The starting weight configuration for the model.
      include_top: Whether to include the final classification layer in the model (set
          to False to use a custom alphabet).
class_docstr_tok: ["A","text","detector","using","the","CRNN","architecture",".","Args",":","alphabet",":","The","alphabet","the","model","should","recognize",".","build_params",":","A","dictionary","of","build","parameters","for","the","model",".","See","`","keras_ocr.recognition.build_model","`","for","details",".","weights",":","The","starting","weight","configuration","for","the","model",".","include_top",":","Whether","to","include","the","final","classification","layer","in","the","model","(","set","to","False","to","use","a","custom","alphabet",")","."]
docstr: Generate batches of training data from an image generator. The generator
  should yield tuples of (image, sentence) where image contains a single
  line of text and sentence is a string representing the contents of
  the image. If a sample weight is desired, it can be provided as a third
  entry in the tuple, making each tuple an (image, sentence, weight) tuple.
  
  Args:
      image_generator: An image / sentence tuple generator. The images should
          be in color even if the OCR is setup to handle grayscale as they
          will be converted here.
      batch_size: How many images to generate at a time.
      lowercase: Whether to convert all characters to lowercase before
          encoding.
docstr_tok: ["Generate","batches","of","training","data","from","an","image","generator",".","The","generator","should","yield","tuples","of","(","image",",","sentence",")","where","image","contains","a","single","line","of","text","and","sentence","is","a","string","representing","the","contents","of","the","image",".","If","a","sample","weight","is","desired",",","it","can","be","provided","as","a","third","entry","in","the","tuple",",","making","each","tuple","an","(","image",",","sentence",",","weight",")","tuple",".","Args",":","image_generator",":","An","image","\/","sentence","tuple","generator",".","The","images","should","be","in","color","even","if","the","OCR","is","setup","to","handle","grayscale","as","they","will","be","converted","here",".","batch_size",":","How","many","images","to","generate","at","a","time",".","lowercase",":","Whether","to","convert","all","characters","to","lowercase","before","encoding","."]
code: def get_batch_generator(
      self, image_generator, batch_size=8, lowercase=False
  ):
      """
      Generate batches of training data from an image generator. The generator
      should yield tuples of (image, sentence) where image contains a single
      line of text and sentence is a string representing the contents of
      the image. If a sample weight is desired, it can be provided as a third
      entry in the tuple, making each tuple an (image, sentence, weight) tuple.
  
      Args:
          image_generator: An image / sentence tuple generator. The images should
              be in color even if the OCR is setup to handle grayscale as they
              will be converted here.
          batch_size: How many images to generate at a time.
          lowercase: Whether to convert all characters to lowercase before
              encoding.
      """
      y = np.zeros((batch_size, 1))
      if self.training_model is None:
          raise Exception(
              "You must first call create_training_model()."
          )
      max_string_length = self.training_model.input_shape[1][1]
      while True:
          batch = [
              sample
              for sample, _ in zip(image_generator, range(batch_size))
          ]
          images: typing.Union[typing.List[np.ndarray], np.ndarray]
          if not self.model.input_shape[-1] == 3:
              images = [
                  cv2.cvtColor(sample[0], cv2.COLOR_RGB2GRAY)[
                      ..., np.newaxis
                  ]
                  for sample in batch
              ]
          else:
              images = [sample[0] for sample in batch]
          images = np.array(
              [image.astype("float32") / 255 for image in images]
          )
          sentences = [sample[1].strip() for sample in batch]
          if lowercase:
              sentences = [sentence.lower() for sentence in sentences]
          for c in "".join(sentences):
              assert c in self.alphabet, f"Found illegal character: {c}"
          assert all(sentences), "Found a zero length sentence."
          assert all(
              len(sentence) <= max_string_length
              for sentence in sentences
          ), "A sentence is longer than this model can predict."
          assert all("  " not in sentence for sentence in sentences), (
              "Strings with multiple sequential spaces are not permitted. "
              "See https://github.com/faustomorales/keras-ocr/issues/54"
          )
          label_length = np.array(
              [len(sentence) for sentence in sentences]
          )[:, np.newaxis]
          labels = np.array(
              [
                  [self.alphabet.index(c) for c in sentence]
                  + [-1] * (max_string_length - len(sentence))
                  for sentence in sentences
              ]
          )
          input_length = np.ones((batch_size, 1)) * max_string_length
          if len(batch[0]) == 3:
              sample_weights = np.array([sample[2] for sample in batch])
              yield (
                  images,
                  labels,
                  input_length,
                  label_length,
              ), y, sample_weights
          else:
              yield (images, labels, input_length, label_length), y
  
file_path: keras-ocr/keras_ocr/recognition.py
imports: import typing
  import string
  import tensorflow
  from tensorflow import keras
  import numpy
  import cv2
  from .None import tools
label_desc: Use image node_id 2 for calling the Recognizer obj's underlying member method code with example usage: obj.get_batch_generator(image_generator, batch_size, lowercase) without return types