code: def create_sprite_image(examples):
      """Returns an encoded sprite image for use in Facets Dive.
  
      Args:
        examples: A list of serialized example protos to get images for.
  
      Returns:
        An encoded PNG.
      """
  
      def generate_image_from_thubnails(thumbnails, thumbnail_dims):
          """Generates a sprite atlas image from a set of thumbnails."""
          num_thumbnails = tf.shape(thumbnails)[0].eval()
          images_per_row = int(math.ceil(math.sqrt(num_thumbnails)))
          thumb_height = thumbnail_dims[0]
          thumb_width = thumbnail_dims[1]
          master_height = images_per_row * thumb_height
          master_width = images_per_row * thumb_width
          num_channels = 3
          master = np.zeros([master_height, master_width, num_channels])
          for idx, image in enumerate(thumbnails.eval()):
              left_idx = idx % images_per_row
              top_idx = int(math.floor(idx / images_per_row))
              left_start = left_idx * thumb_width
              left_end = left_start + thumb_width
              top_start = top_idx * thumb_height
              top_end = top_start + thumb_height
              master[top_start:top_end, left_start:left_end, :] = image
          return tf.image.encode_png(tf.cast(master, dtype=tf.uint8))
  
      image_feature_name = "image/encoded"
      sprite_thumbnail_dim_px = 32
      with tf.compat.v1.Session():
          keys_to_features = {
              image_feature_name: tf.io.FixedLenFeature(
                  (), tf.string, default_value=""
              ),
          }
          parsed = tf.io.parse_example(examples, keys_to_features)
          images = tf.zeros([1, 1, 1, 1], tf.float32)
          i = tf.constant(0)
          thumbnail_dims = (
              sprite_thumbnail_dim_px,
              sprite_thumbnail_dim_px,
          )
          num_examples = tf.constant(len(examples))
          encoded_images = parsed[image_feature_name]
  
          # Loop over all examples, decoding the image feature value, resizing
          # and appending to a list of all images.
          def loop_body(i, encoded_images, images):
              encoded_image = encoded_images[i]
              image = tf.image.decode_jpeg(encoded_image, channels=3)
              resized_image = tf.image.resize(image, thumbnail_dims)
              expanded_image = tf.expand_dims(resized_image, 0)
              images = tf.cond(
                  tf.equal(i, 0),
                  lambda: expanded_image,
                  lambda: tf.concat([images, expanded_image], 0),
              )
              return i + 1, encoded_images, images
  
          loop_out = tf.while_loop(
              lambda i, encoded_images, images: tf.less(
                  i, num_examples
              ),
              loop_body,
              [i, encoded_images, images],
              shape_invariants=[
                  i.get_shape(),
                  encoded_images.get_shape(),
                  tf.TensorShape(None),
              ],
          )
  
          # Create the single sprite atlas image from these thumbnails.
          sprite = generate_image_from_thubnails(
              loop_out[2], thumbnail_dims
          )
          return sprite.eval()
  
imports: from __future__ import division
  from __future__ import print_function
  import collections
  import copy
  import json
  import math
  from absl import logging
  import numpy
  import tensorflow
  from google.protobuf import json_format
  from six import binary_type, string_types, integer_types
  from six import iteritems
  from six.moves import zip
  from inspect import signature
  from utils import common_utils
  from utils import platform_utils
  from tensorflow_serving.apis import classification_pb2
  from tensorflow_serving.apis import inference_pb2
  from tensorflow_serving.apis import regression_pb2
label_desc: Use image node_id 18 for calling a global function with example usage: create_sprite_image(examples) and returns: tf, sprite, unknown,  encoded_images,  images