code: def weights_rearrange(weights):
      """Rearrange weights tensor so that m by n sparsity structure applied in last channel.
  
      This is a m_by_n sparsity helper function.
  
      m by n sparsity: every group of consecutive n values contains
        at least m zeros on the last channel in TFLite data format.
  
      * In case of Conv2D weights:
          TF data format is [height, width, channel_in, channel_out],
          TFLite data format is [channel_out, height, width, channel_in]
        Rearranged Conv2D weights format: [channel_out x height x width, channel_in]
  
      * In case of Dense weights:
          TF data format is [channel_in, channel_out],
          TFLite data format is [width, channel_in]
        Rearranged Conv2D weights format: [width, channel_in]
  
      Args:
        weights: weights tensor. Must be rank 2 or 4.
  
      Returns:
        A rank 2 weight tensor.
  
      Raises:
        ValueError: if the input tensor is not rank 2 or 4.
      """
      if weights.shape.rank == 2:
          prepared_weights = tf.transpose(weights)
      elif weights.shape.rank == 4:
          perm_weights = tf.transpose(weights, perm=[3, 0, 1, 2])
          prepared_weights = tf.reshape(
              perm_weights,
              [tf.reduce_prod(perm_weights.shape[:-1]), -1],
          )
      else:
          raise ValueError(
              f"weight tensor with shape: {weights.shape} is not supported."
          )
  
      return prepared_weights
  
file_path: model-optimization/tensorflow_model_optimization/python/core/sparsity/keras/pruning_utils.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import numpy
  import tensorflow
label_desc: Use image node_id 5 for calling a global function with example usage: weights_rearrange(weights) and returns: prepared_weights