code: def image_generator(images, labels):
      """Generator for images that takes image and labels lists and creates pngs.
  
      Args:
        images: list of images given as [width x height x channels] numpy arrays.
        labels: list of ints, same length as images.
  
      Yields:
        A dictionary representing the images with the following fields:
        * image/encoded: the string encoding the image as PNG,
        * image/format: the string "png" representing image format,
        * image/class/label: an integer representing the label,
        * image/height: an integer representing the height,
        * image/width: an integer representing the width.
        Every field is actually a singleton list of the corresponding type.
  
      Raises:
        ValueError: if images is an empty list.
      """
      if not images:
          raise ValueError(
              "Must provide some images for the generator."
          )
      width, height, _ = images[0].shape
      for enc_image, label in zip(encode_images_as_png(images), labels):
          yield {
              "image/encoded": [enc_image],
              "image/format": ["png"],
              "image/class/label": [int(label)],
              "image/height": [height],
              "image/width": [width],
          }
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import io
  import os
  import numpy
  from tensor2tensor.data_generators import generator_utils
  from tensor2tensor.data_generators import problem
  from tensor2tensor.data_generators import text_encoder
  from tensor2tensor.layers import common_layers
  from tensor2tensor.layers import modalities
  from tensor2tensor.utils import contrib
  from tensor2tensor.utils import metrics
  import tensorflow.compat.v1
label_desc: Use image node_id 8 for calling a global function with example usage: image_generator(images, labels) without return types