class_docstr: Class for Per-channel clustering of Conv2D layers.
class_docstr_tok: ["Class","for","Per-channel","clustering","of","Conv2D","layers","."]
docstr: Returns indices of closest cluster centroids.
  
  This function is based on the function get_pulling_indices
  of the base class ClusteringAlgorithm. We apply each per
  channel of the convolutional layer.
  
  Args:
    weight: ND array of weights. For each weight in this array the closest
      cluster centroids is found.
  
  Returns:
    ND array of the same shape as `weight` parameter of the type
    tf.int32. The returned array contain weight lookup indices.
docstr_tok: ["Returns","indices","of","closest","cluster","centroids",".","This","function","is","based","on","the","function","get_pulling_indices","of","the","base","class","ClusteringAlgorithm",".","We","apply","each","per","channel","of","the","convolutional","layer",".","Args",":","weight",":","ND","array","of","weights",".","For","each","weight","in","this","array","the","closest","cluster","centroids","is","found",".","Returns",":","ND","array","of","the","same","shape","as","`","weight","`","parameter","of","the","type","tf.int32",".","The","returned","array","contain","weight","lookup","indices","."]
code: def get_pulling_indices(self, weight):
      """Returns indices of closest cluster centroids.
  
      This function is based on the function get_pulling_indices
      of the base class ClusteringAlgorithm. We apply each per
      channel of the convolutional layer.
  
      Args:
        weight: ND array of weights. For each weight in this array the closest
          cluster centroids is found.
  
      Returns:
        ND array of the same shape as `weight` parameter of the type
        tf.int32. The returned array contain weight lookup indices.
      """
      channel_indices = []
  
      num_channels = (
          weight.shape[1]
          if self.data_format == "channels_first"
          else weight.shape[-1]
      )
  
      for channel in range(num_channels):
          channel_weights = (
              weight[:, channel, :, :]
              if self.data_format == "channels_first"
              else weight[:, :, :, channel]
          )
          channel_centroids = self.cluster_centroids[channel]
          pulling_indices = super().get_pulling_indices(
              channel_weights, channel_centroids
          )
  
          channel_indices.append(pulling_indices)
  
      pulling_indices = tf.convert_to_tensor(channel_indices)
      pulling_indices = tf.transpose(
          pulling_indices,
          perm=(1, 0, 2, 3)
          if self.data_format == "channels_first"
          else (1, 2, 3, 0),
      )
  
      return pulling_indices
  
file_path: model-optimization/tensorflow_model_optimization/python/core/clustering/keras/clustering_algorithm.py
imports: import abc
  import six
  import tensorflow
  from tensorflow_model_optimization.python.core.clustering.keras.cluster_config import GradientAggregation
label_desc: Use image node_id 1 for calling the ClusteringAlgorithmPerChannel obj's underlying member method code with example usage: obj.get_pulling_indices(weight) and returns: pulling_indices