code: def encode_images_as_png(images):
      """Yield images encoded as pngs."""
      if tf.executing_eagerly():
          for image in images:
              yield tf.image.encode_png(image).numpy()
      else:
          (height, width, channels) = images[0].shape
          with tf.Graph().as_default():
              image_t = tf.placeholder(
                  dtype=tf.uint8, shape=(height, width, channels)
              )
              encoded_image_t = tf.image.encode_png(image_t)
              with tf.Session() as sess:
                  for image in images:
                      enc_string = sess.run(
                          encoded_image_t, feed_dict={image_t: image}
                      )
                      yield enc_string
  
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 7 for calling a global function with example usage: encode_images_as_png(images) without return types