code: def _generator(
      tmp_dir,
      training,
      size=_BASE_EXAMPLE_IMAGE_SIZE,
      training_fraction=0.95,
  ):
      """Base problem example generator for Allen Brain Atlas problems.
  
      Args:
  
        tmp_dir: str, a directory where raw example input data has been stored.
        training: bool, whether the mode of operation is training (or,
          alternatively, evaluation), determining whether examples in tmp_dir
          prefixed with train or dev will be used.
        size: int, the image size to add to the example annotation.
        training_fraction: float, the fraction of the sub-image path list to
          consider as the basis for training examples.
  
      Yields:
        A dictionary representing the images with the following fields:
          * image/encoded: The string encoding the image as JPEG.
          * image/format: The string "jpeg" indicating the image format.
          * image/height: The integer indicating the image height.
          * image/width: The integer indicating the image height.
  
      """
  
      maybe_download_image_dataset(_IMAGE_IDS, tmp_dir)
  
      image_files = _get_case_file_paths(
          tmp_dir=tmp_dir,
          case=training,
          training_fraction=training_fraction,
      )
  
      image_obj = PIL_Image()
  
      tf.logging.info(
          "Loaded case file paths (n=%s)" % len(image_files)
      )
      height = size
      width = size
  
      for input_path in image_files:
          img = image_obj.open(input_path)
          img = np.float32(img)
          shape = np.shape(img)
  
          for h_index in range(0, int(math.floor(shape[0] / size))):
              h_offset = h_index * size
              h_end = h_offset + size - 1
  
              for v_index in range(0, int(math.floor(shape[1] / size))):
                  v_offset = v_index * size
                  v_end = v_offset + size - 1
  
                  # Extract a sub-image tile.
                  subimage = np.uint8(
                      img[h_offset:h_end, v_offset:v_end]
                  )  # pylint: disable=invalid-sequence-index
  
                  # Filter images that are likely background (not tissue).
                  if np.amax(subimage) < 230:
                      continue
  
                  subimage = image_obj.fromarray(subimage)
                  buff = BytesIO()
                  subimage.save(buff, format="JPEG")
                  subimage_encoded = buff.getvalue()
  
                  yield {
                      "image/encoded": [subimage_encoded],
                      "image/format": ["jpeg"],
                      "image/height": [height],
                      "image/width": [width],
                  }
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from io import BytesIO
  import math
  import os
  import numpy
  import requests
  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.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 5 for calling a global function with example usage: _generator(tmp_dir, training, size, training_fraction) without return types