code: def bigdl_estimator():
      from zoo.orca.learn.bigdl.estimator import Estimator
      from tensorflow.python.keras.datasets import imdb
      from tensorflow.python.keras.preprocessing import sequence
      from zoo.pipeline.api.keras.models import Model
      from zoo.pipeline.api.keras.objectives import (
          SparseCategoricalCrossEntropy,
      )
      from zoo.orca.data import XShards
      from zoo.orca.learn.metrics import Accuracy
      import numpy as np
  
      # conf = {"spark.executor.extraJavaOptions": "-Xss512m", "spark.driver.extraJavaOptions": "-Xss512m"}
  
      # init_orca_context(cluster_mode="local", cores=8, memory="16g")
      init_orca_context(cluster_mode="local", cores=4, memory="16g")
      max_features = 200
      max_len = 20
  
      print("running bigdl estimator")
  
      (x_train, y_train), (x_test, y_test) = imdb.load_data(
          num_words=max_features
      )
  
      x_train = x_train[:1000]
      y_train = y_train[:1000]
      x_test = x_test[-1000:]
      y_test = y_test[-1000:]
  
      print(len(x_train), "train sequences")
      print(len(x_test), "test sequences")
  
      print("Pad sequences (samples x time)")
      x_train = sequence.pad_sequences(x_train, maxlen=max_len)
      x_test = sequence.pad_sequences(x_test, maxlen=max_len)
      print("x_train shape:", x_train.shape)
      print("x_test shape:", x_test.shape)
  
      train_pos = np.zeros((len(x_train), max_len), dtype=np.int32)
      val_pos = np.zeros((len(x_test), max_len), dtype=np.int32)
      for i in range(0, len(x_train)):
          train_pos[i, :] = np.arange(max_len)
          val_pos[i, :] = np.arange(max_len)
  
      train_dataset = XShards.partition(
          {"x": (x_train, train_pos), "y": np.array(y_train)}
      )
      val_dataset = XShards.partition(
          {"x": (x_test, val_pos), "y": np.array(y_test)}
      )
  
      token_shape = (max_len,)
      position_shape = (max_len,)
      token_input = Input(shape=token_shape)
      position_input = Input(shape=position_shape)
      O_seq = TransformerLayer.init(
          vocab=max_features, hidden_size=128, n_head=8, seq_len=max_len
      )([token_input, position_input])
      # Select the first output of the Transformer. The second is the pooled output.
      O_seq = SelectTable(0)(O_seq)
      O_seq = GlobalAveragePooling1D()(O_seq)
      O_seq = Dropout(0.2)(O_seq)
      outputs = Dense(2, activation="softmax")(O_seq)
  
      model = Model([token_input, position_input], outputs)
      model.summary()
      batch_size = 64
      print("Train started")
      est = Estimator.from_bigdl(
          model=model,
          loss=SparseCategoricalCrossEntropy(),
          optimizer=Adam(),
          metrics=[Accuracy()],
      )
      est.set_constant_gradient_clipping(0.1, 0.2)
      est.fit(data=train_dataset, batch_size=batch_size, epochs=1)
      result = est.evaluate(val_dataset)
      print(result)
      est.clear_gradient_clipping()
      est.set_l2_norm_gradient_clipping(0.5)
      est.fit(data=train_dataset, batch_size=batch_size, epochs=1)
      print("Train finished")
  
      print("Evaluating started")
      result = est.evaluate(val_dataset)
      print(result)
      print("Evaluating finished")
      est.save("work/saved_model")
      # est.load('work/saved_model')
      print("load and save API finished")
  
      est.get_train_summary(tag="Loss")
      est.get_validation_summary(tag="Top1Accuracy")
      print("get summary API finished")
  
      stop_orca_context()
  
file_path: BigDL/ppml/trusted-big-data-ml/python/docker-graphene/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 1 for calling a global function with example usage: bigdl_estimator() without return types