code: def test_model_quantize_ptq(self):
      model = MobileNetV2(
          weights=None, input_shape=[40, 40, 3], classes=10
      )
      model = Model(inputs=model.inputs, outputs=model.outputs)
      model.compile(
          optimizer=tf.keras.optimizers.Adam(learning_rate=1e-3),
          loss=tf.keras.losses.BinaryCrossentropy(),
          metrics=[tf.keras.metrics.CategoricalAccuracy()],
      )
      train_examples = np.random.random((100, 40, 40, 3))
      train_labels = np.random.randint(0, 10, size=(100,))
      train_labels = to_categorical(train_labels, num_classes=10)
      train_dataset = tf.data.Dataset.from_tensor_slices(
          (train_examples, train_labels)
      )
      # Case 1: Default
      q_model = InferenceOptimizer.quantize(model, x=train_dataset)
      assert q_model
      output = q_model(train_examples[0:10])
      assert output.shape == (10, 10)
  
      # Case 2: Override by arguments
      q_model = InferenceOptimizer.quantize(
          model,
          x=train_dataset,
          metric=tf.keras.metrics.CategoricalAccuracy(),
          tuning_strategy="basic",
          accuracy_criterion={
              "relative": 0.99,
              "higher_is_better": True,
          },
      )
      assert q_model
      output = q_model(train_examples[0:10])
      assert output.shape == (10, 10)
  
      # Case 3: Save and load
      with tempfile.TemporaryDirectory() as tmp_dir:
          InferenceOptimizer.save(q_model, tmp_dir)
          loaded_model = InferenceOptimizer.load(tmp_dir, model)
      output2 = loaded_model(train_examples[0:10])
      assert output2.shape == (10, 10)
      np.testing.assert_almost_equal(
          output.numpy(), output2.numpy(), decimal=5
      )
  
      # Case 4: Invalid approach, dynamic or qat is not supported
      invalid_approach = "dynamic"
      with pytest.raises(
          RuntimeError, match="Only 'static' approach is supported now."
      ):
          InferenceOptimizer.quantize(
              model, x=None, approach=invalid_approach
          )
  
file_path: BigDL/python/nano/test/inc/tf/test_keras_quantize.py
imports: import pytest
  import operator
  import tempfile
  from unittest import TestCase
  import tensorflow
  from tensorflow.keras.applications.mobilenet_v2 import MobileNetV2
  from keras.utils.np_utils import to_categorical
  import numpy
  from bigdl.nano.tf.keras import Model, InferenceOptimizer
  from bigdl.nano.utils.common import compare_version
label_desc: Use image node_id 1 for calling the TestModelQuantize obj's underlying member method code with example usage: obj.test_model_quantize_ptq() without return types