docstr: Cluster the (sparse) model and return clustered_model.
docstr_tok: ["Cluster","the","(","sparse",")","model","and","return","clustered_model","."]
code: def _get_clustered_model(self, preserve_sparsity):
      """Cluster the (sparse) model and return clustered_model."""
      tf.random.set_seed(1)
      original_model = tf.keras.Sequential(
          [
              layers.Dense(5, activation="softmax", input_shape=(10,)),
              layers.Flatten(),
          ]
      )
  
      # Manually set sparsity in the Dense layer if preserve_sparsity is on
      if preserve_sparsity:
          first_layer_weights = original_model.layers[0].get_weights()
          first_layer_weights[0][:][0:2] = 0.0
          original_model.layers[0].set_weights(first_layer_weights)
  
      # Start the sparsity-aware clustering
      clustering_params = {
          "number_of_clusters": 4,
          "cluster_centroids_init": cluster_config.CentroidInitialization.LINEAR,
          "preserve_sparsity": True,
      }
  
      clustered_model = experimental_cluster.cluster_weights(
          original_model, **clustering_params
      )
  
      return clustered_model
  
imports: from absl.testing import parameterized
  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.clustering.keras.experimental import cluster
  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 5 for calling the ClusterPreserveIntegrationTest obj's underlying member method code with example usage: obj._get_clustered_model(preserve_sparsity) and returns: clustered_model