code: def _get_tf_examples_serving_signature(
      model, schema, tf_transform_output
  ):
      """Returns a serving signature that accepts `tensorflow.Example`."""
  
      if (
          tf_transform_output is None
      ):  # Transform component is not used.
  
          @tf.function(
              input_signature=[
                  tf.TensorSpec(
                      shape=[None], dtype=tf.string, name="examples"
                  )
              ]
          )
          def serve_tf_examples_fn(serialized_tf_example):
              """Returns the output to be used in the serving signature."""
              raw_feature_spec = schema_utils.schema_as_feature_spec(
                  schema
              ).feature_spec
              # Remove label feature since these will not be present at serving time.
              raw_feature_spec.pop(features.LABEL_KEY)
              raw_features = tf.io.parse_example(
                  serialized_tf_example, raw_feature_spec
              )
              logging.info("serve_features = %s", raw_features)
  
              outputs = model(raw_features)
              # TODO(b/154085620): Convert the predicted labels from the model using a
              # reverse-lookup (opposite of transform.py).
              return {"outputs": outputs}
  
      else:  # Transform component exists.
          # We need to track the layers in the model in order to save it.
          # TODO(b/162357359): Revise once the bug is resolved.
          model.tft_layer_inference = (
              tf_transform_output.transform_features_layer()
          )
  
          @tf.function(
              input_signature=[
                  tf.TensorSpec(
                      shape=[None], dtype=tf.string, name="examples"
                  )
              ]
          )
          def serve_tf_examples_fn(serialized_tf_example):
              """Returns the output to be used in the serving signature."""
              raw_feature_spec = tf_transform_output.raw_feature_spec()
              # Remove label feature since these will not be present at serving time.
              raw_feature_spec.pop(features.LABEL_KEY)
              raw_features = tf.io.parse_example(
                  serialized_tf_example, raw_feature_spec
              )
              transformed_features = model.tft_layer_inference(
                  raw_features
              )
              logging.info(
                  "serve_transformed_features = %s",
                  transformed_features,
              )
  
              outputs = model(transformed_features)
              # TODO(b/154085620): Convert the predicted labels from the model using a
              # reverse-lookup (opposite of transform.py).
              return {"outputs": outputs}
  
      return serve_tf_examples_fn
  
file_path: tfx/tfx/experimental/templates/penguin/models/model.py
imports: from typing import List
  from absl import logging
  import tensorflow
  from tensorflow import keras
  import tensorflow_transform
  from tensorflow_transform.tf_metadata import schema_utils
  from tfx import v1
  from tfx.experimental.templates.penguin.models import constants
  from tfx.experimental.templates.penguin.models import features
  from tfx_bsl.public import tfxio
  from tensorflow_metadata.proto.v0 import schema_pb2
label_desc: Use image node_id 1 for calling a global function with example usage: _get_tf_examples_serving_signature(model, schema, tf_transform_output) and returns: serve_tf_examples_fn, dict, dict