class_docstr: Weight clustering compression module config.
class_docstr_tok: ["Weight","clustering","compression","module","config","."]
docstr: Init function from pre-trained model case.
docstr_tok: ["Init","function","from","pre-trained","model","case","."]
code: def init_training_weights(self, pretrained_weight: tf.Tensor):
      """Init function from pre-trained model case."""
      centroid_initializer = clustering_centroids.CentroidsInitializerFactory.get_centroid_initializer(
          self.cluster_centroids_init
      )(
          pretrained_weight, self.number_of_clusters
      )
  
      cluster_centroids = centroid_initializer.get_cluster_centroids()
  
      if len(pretrained_weight.shape) == 2:
          clustering_impl_cls = DenseWeightsCA
      elif len(pretrained_weight.shape) == 4:
          clustering_impl_cls = ConvolutionalWeightsCA
      else:
          raise NotImplementedError(
              "Only for dimension=2 or 4 is supported."
          )
  
      clustering_impl = clustering_impl_cls(cluster_centroids)
  
      # We find the nearest cluster centroids and store them so that ops can
      # build their weights upon it. These indices are calculated once and
      # stored forever. We use to make look-ups from self.cluster_centroids_tf
      pulling_indices = clustering_impl.get_pulling_indices(
          pretrained_weight
      )
  
      self.add_training_weight(
          name="cluster_centroids",
          shape=cluster_centroids.shape,
          dtype=cluster_centroids.dtype,
          initializer=tf.keras.initializers.Constant(cluster_centroids),
      )
      self.add_training_weight(
          name="pulling_indices",
          shape=pulling_indices.shape,
          dtype=pulling_indices.dtype,
          initializer=tf.keras.initializers.Constant(pulling_indices),
      )
  
file_path: model-optimization/tensorflow_model_optimization/python/core/common/keras/compression/algorithms/weight_clustering.py
imports: from typing import List
  import tensorflow
  from tensorflow_model_optimization.python.core.clustering.keras import clustering_centroids
  from tensorflow_model_optimization.python.core.clustering.keras import clustering_registry
  from tensorflow_model_optimization.python.core.clustering.keras.cluster_config import GradientAggregation
  from tensorflow_model_optimization.python.core.common.keras.compression import algorithm
label_desc: Use image node_id 2 for calling the WeightClustering obj's underlying member method code with example usage: obj.init_training_weights(pretrained_weight) without return types