code: def get_centroids(layer, weight, data_format):
      """Gets centroid infos from the weights of a layer.
  
      Args:
        layer: The Keras layer from which the weight belong.
        weight: The weight tensor to get the centroids info from.
        data_format: string to indicate format: "channels_first" or "channels_last".
      Returns:
        A 4-tuple of centroids (unique values), number of centroids, lookup index,
        whether to cluster per channel (boolean).
      """
      cluster_per_channel = layer.layer and isinstance(
          layer.layer, tf.keras.layers.Conv2D
      )
  
      if not cluster_per_channel:
          centroids, index = get_unique(weight)
          return centroids, tf.size(centroids), index, False
  
      # In case of cluster_per_channel we need to extract
      # unique values (centroids) for each channel.
      num_channels = weight.shape[
          1 if data_format == "channels_first" else -1
      ]
      channel_centroids = []
      channel_indices = []
      num_centroids = []
  
      for channel in range(num_channels):
          channel_weights = weight[:, :, :, channel]
          centroids, indices = get_unique(channel_weights)
  
          channel_centroids.append(centroids)
          channel_indices.append(indices)
          num_centroids.append(tf.size(centroids))
  
      max_centroid = max(num_centroids)
      max_diff = max_centroid - min(num_centroids)
  
      if max_diff > 1:
          centroids, index = get_unique(weight)
          return centroids, tf.size(centroids), index, False
  
      for i, centroid in enumerate(channel_centroids):
          if num_centroids[i] != max_centroid:
              one_padding = tf.ones([max_centroid - num_centroids[i]])
              channel_centroids[i] = tf.concat(
                  [centroid, one_padding], 0
              )
  
      centroids = tf.convert_to_tensor(channel_centroids)
      lookup = tf.convert_to_tensor(channel_indices)
  
      lookup = tf.transpose(
          lookup,
          perm=(1, 0, 2, 3)
          if data_format == "channels_first"
          else (1, 2, 3, 0),
      )
  
      return centroids, max_centroid, lookup, True
  
imports: import logging
  import warnings
  import tensorflow
  from tensorflow_model_optimization.python.core.clustering.keras import cluster_config
  from tensorflow_model_optimization.python.core.clustering.keras import clustering_registry
  from tensorflow_model_optimization.python.core.quantization.keras import quant_ops
  from tensorflow_model_optimization.python.core.quantization.keras import quantizers
  from tensorflow_model_optimization.python.core.quantization.keras.default_8bit import default_8bit_quantize_registry
  from tensorflow_model_optimization.python.core.quantization.keras.default_8bit import default_8bit_quantizers
label_desc: Use image node_id 2 for calling a global function with example usage: get_centroids(layer, weight, data_format) and returns: centroids,  max_centroid,  lookup,  True, centroids,  tf,  index,  False, centroids,  tf,  index,  False