import tensorflow as tf

    """Preprocess a single raw image."""
    image = tf.image.decode_image(encoded_image, channels=shape[-1])
    image.set_shape(shape)
    return tf.cast(image, dtype)

  def serving_input_receiver_fn():
    image_bytes_list = tf.placeholder(
        shape=[None],
        dtype=tf.string,
    )
    images = tf.map_fn(
        _preprocess_image, image_bytes_list, back_prop=False, dtype=dtype)
    return tf.estimator.export.TensorServingInputReceiver(
        features=images, receiver_tensors=image_bytes_list)

  return serving_input_receiver_fn


def _encode_image(image_array, fmt='PNG'):
  """encodes an (numpy) image array to string.

  Args:
    image_array: (numpy) image array
    fmt: image format to use
