code: def simple_custom_estimator(export_path, eval_export_path):
      """Trains and exports a simple custom estimator."""
  
      def model_fn(features, labels, mode, config):
          """Model function for custom estimator."""
          del config
          m = tf.Variable(0.0, dtype=tf.float32, name="m")
          c = tf.Variable(0.0, dtype=tf.float32, name="c")
          predictions = m * features["age"] + c
  
          if mode == tf_estimator.ModeKeys.PREDICT:
              return tf_estimator.EstimatorSpec(
                  mode=mode,
                  predictions={"score": predictions},
                  export_outputs={
                      "score": tf_estimator.export.RegressionOutput(
                          predictions
                      )
                  },
              )
  
          loss = tf.compat.v1.losses.mean_squared_error(
              labels, predictions
          )
          eval_metric_ops = {
              "mean_absolute_error": tf.compat.v1.metrics.mean_absolute_error(
                  tf.cast(labels, tf.float64),
                  tf.cast(predictions, tf.float64),
              ),
              "mean_prediction": tf.compat.v1.metrics.mean(predictions),
              "mean_label": tf.compat.v1.metrics.mean(labels),
          }
  
          optimizer = tf.compat.v1.train.GradientDescentOptimizer(
              learning_rate=0.001
          )
          train_op = optimizer.minimize(
              loss=loss,
              global_step=tf.compat.v1.train.get_global_step(),
          )
  
          return tf_estimator.EstimatorSpec(
              mode=mode,
              loss=loss,
              train_op=train_op,
              eval_metric_ops=eval_metric_ops,
              predictions=predictions,
          )
  
      def train_input_fn():
          """Train input function."""
          return (
              {
                  "age": tf.constant([[1.0], [2.0], [3.0], [4.0]]),
              },
              tf.constant([[4.0], [7.0], [10.0], [13.0]]),
          )
  
      def serving_input_receiver_fn():
          """Serving input receiver function."""
          serialized_tf_example = tf.compat.v1.placeholder(
              dtype=tf.string, shape=[None], name="input_example_tensor"
          )
          feature_spec = {
              "age": tf.io.FixedLenFeature([1], dtype=tf.float32)
          }
          receiver_tensors = {"examples": serialized_tf_example}
          features = tf.io.parse_example(
              serialized=serialized_tf_example, features=feature_spec
          )
          return tf_estimator.export.ServingInputReceiver(
              features, receiver_tensors
          )
  
      def eval_input_receiver_fn():
          """Eval input receiver function."""
          serialized_tf_example = tf.compat.v1.placeholder(
              dtype=tf.string, shape=[None], name="input_example_tensor"
          )
          feature_spec = {
              "age": tf.io.FixedLenFeature([1], dtype=tf.float32),
              "label": tf.io.FixedLenFeature([1], dtype=tf.float32),
          }
          receiver_tensors = {"examples": serialized_tf_example}
          features = tf.io.parse_example(
              serialized=serialized_tf_example, features=feature_spec
          )
  
          return export.EvalInputReceiver(
              features=features,
              labels=features["label"],
              receiver_tensors=receiver_tensors,
          )
  
      estimator = tf_estimator.Estimator(model_fn=model_fn)
      estimator.train(input_fn=train_input_fn, steps=1000)
  
      return util.export_model_and_eval_model(
          estimator=estimator,
          serving_input_receiver_fn=serving_input_receiver_fn,
          eval_input_receiver_fn=eval_input_receiver_fn,
          export_path=export_path,
          eval_export_path=eval_export_path,
      )
  
imports: import tensorflow
  from tensorflow import estimator
  from tensorflow_model_analysis.eval_saved_model import export
  from tensorflow_model_analysis.eval_saved_model.example_trainers import util
label_desc: Use image node_id 1 for calling a global function with example usage: simple_custom_estimator(export_path, eval_export_path) and returns: util, tf_estimator, dict,  tf, tf_estimator, export, tf_estimator