code: def main(unused_args):
      # Load the MNIST dataset.
      mnist = tf.keras.datasets.mnist
      # Shuffle and split data to generate training and testing datasets
      (train_images, train_labels), (
          test_images,
          test_labels,
      ) = mnist.load_data()
      # Normalize the input images so that each pixel value is between 0 and 1.
      train_images = train_images / 255.0
      test_images = test_images / 255.0
  
      input_shape = (28, 28)
      # Create and train the baseline model
      model = setup_model(input_shape, train_images, train_labels)
      # Apply clustering API and retrain the model
      clustered_model = cluster_model(model, train_images, train_labels)
      print("Apply clustering:")
      clst_acc = evaluate_model_fp32(
          clustered_model, test_images, test_labels
      )
      clustered_model_stripped = tfmot_cluster.strip_clustering(
          clustered_model
      )
      print(
          "Apply cluster-preserve quantization aware training (cqat):"
      )
      # Start from pretrained clustered model, apply CQAT API, retrain the model
      cqat_model = cluster_preserve_quantize_model(
          clustered_model_stripped, train_images, train_labels
      )
      cqat_acc = evaluate_model_fp32(
          cqat_model, test_images, test_labels
      )
      # This only removes extra variables introduced by clustering
      # but the quantize_wrapper stays
      cqat_model_stripped = strip_clustering_cqat(cqat_model)
  
      # Compare between clustering and cqat in terms of FP32 accuracy
      # and numbers of unique weights
      print("FP32 accuracy of clustered model:", clst_acc)
      print_unique_weights(clustered_model_stripped)
      print("FP32 accuracy of cqat model:", cqat_acc)
      print_unique_weights(cqat_model_stripped)
  
      # See consistency of accuracy from TF to TFLite
      converter = tf.lite.TFLiteConverter.from_keras_model(
          cqat_model_stripped
      )
      converter.optimizations = [tf.lite.Optimize.DEFAULT]
      cqat_model_stripped_tflite = converter.convert()
      interpreter = tf.lite.Interpreter(
          model_content=cqat_model_stripped_tflite
      )
      interpreter.allocate_tensors()
      test_accuracy = evaluate_model(
          interpreter, test_images, test_labels
      )
  
      with open("cqat.tflite", "wb") as f:
          f.write(cqat_model_stripped_tflite)
  
      print("CQAT TFLite test_accuracy:", test_accuracy)
      print("CQAT TF test accuracy:", cqat_acc)
  
file_path: model-optimization/tensorflow_model_optimization/python/examples/cluster_preserve_qat/keras/mnist_cnn.py
imports: from __future__ import print_function
  import os
  from absl import app
  import numpy
  import tensorflow
  from tensorflow_model_optimization.python.core.clustering.keras import cluster
  from tensorflow_model_optimization.python.core.clustering.keras import cluster_config
  from tensorflow_model_optimization.python.core.quantization.keras import quantize
  from tensorflow_model_optimization.python.core.quantization.keras.collab_opts.cluster_preserve import default_8bit_cluster_preserve_quantize_scheme
  from tensorflow_model_optimization.python.core.quantization.keras.collab_opts.cluster_preserve.cluster_utils import strip_clustering_cqat
label_desc: Use image node_id 9 for calling a global function with example usage: main(unused_args) without return types