code: def tf_estimator():
      from zoo.orca.learn.tf.estimator import Estimator
  
      init_orca_context(cluster_mode="local", cores=4, memory="3g")
  
      os.environ["HDF5_USE_FILE_LOCKING"] = "FALSE"
  
      print("running tf estimator")
  
      imdb = keras.datasets.imdb
      (train_data, train_labels), (
          test_data,
          test_labels,
      ) = imdb.load_data(num_words=1000)
      # print(train_data)
      word_index = imdb.get_word_index()
      word_index = {k: (v + 3) for k, v in word_index.items()}
      word_index["<PAD>"] = 0
      word_index["<START>"] = 1
      word_index["<UNK>"] = 2  # unknown
      word_index["<UNUSED>"] = 3
  
      train_data = keras.preprocessing.sequence.pad_sequences(
          train_data,
          value=word_index["<PAD>"],
          padding="post",
          maxlen=256,
      )
  
      test_data = keras.preprocessing.sequence.pad_sequences(
          test_data,
          value=word_index["<PAD>"],
          padding="post",
          maxlen=256,
      )
  
      model = keras.Sequential()
      model.add(keras.layers.Embedding(1000, 16))
      model.add(keras.layers.GlobalAveragePooling1D())
      model.add(keras.layers.Dense(16, activation=tf.nn.relu))
      model.add(keras.layers.Dense(1, activation=tf.nn.sigmoid))
  
      model.summary()
  
      model.compile(
          optimizer="adam", loss="binary_crossentropy", metrics=["acc"]
      )
  
      x_val = train_data[:1000]
      partial_x_train = train_data[1000:]
  
      y_val = train_labels[:1000]
      partial_y_train = train_labels[1000:]
  
      train_dataset = tf.data.Dataset.from_tensor_slices(
          (partial_x_train, partial_y_train)
      )
      validation_dataset = tf.data.Dataset.from_tensor_slices(
          (x_val, y_val)
      )
      est = Estimator.from_keras(keras_model=model)
      est.set_constant_gradient_clipping(0.1, 0.2)
      est.fit(
          data=train_dataset,
          batch_size=512,
          epochs=5,
          validation_data=validation_dataset,
      )
      results = est.evaluate(validation_dataset)
      print(results)
      est.clear_gradient_clipping()
      est.set_l2_norm_gradient_clipping(0.1)
      est.fit(
          data=train_dataset,
          batch_size=512,
          epochs=5,
          validation_data=validation_dataset,
      )
      results = est.evaluate(validation_dataset)
      print(results)
      est.save("work/saved_model")
      print("save API finished")
      # est.save_tf_checkpoint('work/checkpoint')
      # est.load_tf_checkpoint('work/checkpoint')
      print("checkpoint save and load API finished")
      est.save_keras_model("work/keras_model")
      est.save_keras_weights("work/keras_weights")
      print("keras model and weights save API finished")
      # est.load_keras_model('work/keras_model')
      # est.load_keras_weights('work')
      print("keras model and weights load API finished")
      est.get_train_summary(tag="Loss")
      est.get_validation_summary(tag="Top1Accuracy")
      # Estimator.load(est, model_path='work/') # Has not been implemented
      # resutls = est.predict(validation_dataset)
      # print(results)
  
      stop_orca_context()
  
file_path: BigDL/ppml/trusted-big-data-ml/python/docker-gramine/base/examples/orca_api_example.py
imports: from zoo.orca import init_orca_context, stop_orca_context
  from tensorflow import keras
  from zoo.pipeline.api.keras.layers import *
  import argparse
  import tensorflow
  import os
label_desc: Use image node_id 2 for calling a global function with example usage: tf_estimator() without return types