code: def test_compile_model(self):
      from tensorflow.keras.metrics import CategoricalAccuracy
  
      inputs = tf.keras.Input(shape=(28 * 28,), name="digits")
      x = layers.Dense(10, name="dense_logits")(inputs)
      outputs = layers.Activation(
          "softmax", dtype="float32", name="predictions"
      )(x)
      # test model with metrics in subprocess
      model = Model(inputs=inputs, outputs=outputs)
      model.compile(
          loss="sparse_categorical_crossentropy",
          optimizer=tf.keras.optimizers.RMSprop(),
          metrics=CategoricalAccuracy(),
      )
  
      x = np.random.random((100, 28 * 28))
      y = np.random.randint(0, 10, 100)
  
      infer_opt = InferenceOptimizer()
      infer_opt.optimize(
          model,
          x=x,
          y=y,
          batch_size=1,
          metric=CategoricalAccuracy(),
          direction="max",
          includes=["static_int8"],
      )
      assert (
          infer_opt.optimized_model_dict["static_int8"]["status"]
          == "successful"
      )
  
      # test model without metrics in subprocess
      model = Model(inputs=inputs, outputs=outputs)
      model.compile(
          loss="sparse_categorical_crossentropy",
          optimizer=tf.keras.optimizers.RMSprop(),
      )
  
      infer_opt = InferenceOptimizer()
      infer_opt.optimize(
          model,
          x=x,
          y=y,
          batch_size=1,
          metric=CategoricalAccuracy(),
          direction="max",
          includes=["static_int8"],
      )
      assert (
          infer_opt.optimized_model_dict["static_int8"]["status"]
          == "successful"
      )
  
file_path: BigDL/python/nano/test/tf/inference/test_inf_optimizer.py
imports: from unittest import TestCase
  import tensorflow
  import tempfile
  import os
  from bigdl.nano.tf.keras import InferenceOptimizer
  import numpy
  from tensorflow.keras.applications import MobileNetV2
  from tensorflow.keras import layers, Model
label_desc: Use image node_id 8 for calling the TestInferencePipeline obj's underlying member method code with example usage: obj.test_compile_model() without return types