code: def test_model_to_estimator(
      self, weights_feature_name, serving_default
  ):
      keras_model = model.create_keras_model(
          network=self._network,
          loss=self._loss,
          metrics=self._eval_metrics,
          optimizer=self._optimizer,
          size_feature_name=_SIZE,
      )
      estimator = estimator_lib.model_to_estimator(
          model=keras_model,
          config=self._config,
          weights_feature_name=weights_feature_name,
          custom_objects=self._custom_objects,
          serving_default=serving_default,
      )
      self.assertIsInstance(estimator, tf_compat_v1_estimator.Estimator)
  
      # Train and export model.
      train_spec = tf_estimator.TrainSpec(
          input_fn=self._make_input_fn(weights_feature_name),
          max_steps=1,
      )
      eval_spec = tf_estimator.EvalSpec(
          name="eval",
          input_fn=self._make_input_fn(weights_feature_name),
          steps=10,
      )
      tf_estimator.train_and_evaluate(estimator, train_spec, eval_spec)
  
      context_feature_spec = tf.feature_column.make_parse_example_spec(
          self._context_feature_columns.values()
      )
      example_feature_spec = tf.feature_column.make_parse_example_spec(
          self._example_feature_columns.values()
      )
  
      def _make_serving_input_fn(serving_default):
          if serving_default == "predict":
              return data.build_ranking_serving_input_receiver_fn(
                  data.ELWC,
                  context_feature_spec=context_feature_spec,
                  example_feature_spec=example_feature_spec,
                  size_feature_name=_SIZE,
              )
          else:
  
              def pointwise_serving_fn():
                  serialized = tf.compat.v1.placeholder(
                      dtype=tf.string,
                      shape=[None],
                      name="input_ranking_tensor",
                  )
                  receiver_tensors = {"input_ranking_data": serialized}
                  features = data.parse_from_tf_example(
                      serialized,
                      context_feature_spec=context_feature_spec,
                      example_feature_spec=example_feature_spec,
                      size_feature_name=_SIZE,
                  )
                  return tf_estimator.export.ServingInputReceiver(
                      features, receiver_tensors
                  )
  
              return pointwise_serving_fn
  
      serving_input_receiver_fn = _make_serving_input_fn(
          serving_default
      )
      export_dir = os.path.join(
          tf.compat.v1.test.get_temp_dir(), "export"
      )
      estimator.export_saved_model(
          export_dir, serving_input_receiver_fn
      )
  
      # Confirm model ran and created checkpoints and saved model.
      final_ckpt_path = os.path.join(
          estimator.model_dir, "model.ckpt-1.meta"
      )
      self.assertTrue(tf.io.gfile.exists(final_ckpt_path))
  
      saved_model_pb = os.path.join(
          export_dir,
          tf.io.gfile.listdir(export_dir)[0],
          "saved_model.pb",
      )
      self.assertTrue(tf.io.gfile.exists(saved_model_pb))
  
imports: import os
  from absl.testing import parameterized
  import tensorflow
  from tensorflow import estimator
  from tensorflow.compat.v1 import estimator
  from google.protobuf import text_format
  from tensorflow_ranking.python import data
  from tensorflow_ranking.python.keras import estimator
  from tensorflow_ranking.python.keras import losses
  from tensorflow_ranking.python.keras import metrics
  from tensorflow_ranking.python.keras import model
  from tensorflow_ranking.python.keras import network
  from tensorflow_serving.apis import input_pb2
label_desc: Use image node_id 5 for calling the KerasModelToEstimatorTest obj's underlying member method code with example usage: obj.test_model_to_estimator(weights_feature_name, serving_default) and returns: data, pointwise_serving_fn, tf_estimator