code: def testWeightClustering_TrainingE2E(self):
      number_of_clusters = 8
      model = _build_model()
      _train_model(model)
      original_saved_model_dir = _save_as_saved_model(model)
  
      algorithm = weight_clustering.WeightClustering(
          number_of_clusters=number_of_clusters,
          cluster_centroids_init=cluster_config.CentroidInitialization.DENSITY_BASED,
      )
      compressed_model = algorithm.compress_model(model)
  
      _train_model(compressed_model)
  
      saved_model_dir = _save_as_saved_model(compressed_model)
  
      _, (x_test, y_test) = _get_dataset()
  
      loss_fn = tf.keras.losses.SparseCategoricalCrossentropy(
          from_logits=True
      )
  
      compressed_model.compile(
          optimizer="adam", loss=loss_fn, metrics=["accuracy"]
      )
  
      results = compressed_model.evaluate(x_test, y_test)
  
      # Accuracy test.
      self.assertGreater(results[1], 0.85)  # 0.8708
  
      original_size = _get_zipped_directory_size(
          original_saved_model_dir
      )
      compressed_size = _get_zipped_directory_size(saved_model_dir)
  
      # Compressed model size test.
      self.assertLess(compressed_size, original_size / 4.0)
  
file_path: model-optimization/tensorflow_model_optimization/python/core/common/keras/compression/algorithms/weight_clustering_test.py
imports: import os
  import tempfile
  import zipfile
  import tensorflow
  from tensorflow_model_optimization.python.core.clustering.keras import cluster_config
  from tensorflow_model_optimization.python.core.common.keras.compression.algorithms import weight_clustering
label_desc: Use image node_id 1 for calling the FunctionalTest obj's underlying member method code with example usage: obj.testWeightClustering_TrainingE2E() without return types