code: def main(unused_argv):
      ##############################################################################
      # Prepare training and testing data
      ##############################################################################
      (
          (x_train, y_train),
          (x_test, y_test),
          input_shape,
      ) = keras_test_utils.get_preprocessed_mnist_data()
  
      ##############################################################################
      # Train a model with sparsity 2x4.
      ##############################################################################
      pruning_params = {
          "pruning_schedule": ConstantSparsity(
              0.5, begin_step=0, frequency=100
          ),
          "sparsity_m_by_n": (2, 4),
      }
  
      model = build_layerwise_model(input_shape, **pruning_params)
      pruned_model = train(model, x_train, y_train, x_test, y_test)
  
      # Write a model that has been pruned with 2x4 sparsity.
      converter = tf.lite.TFLiteConverter.from_keras_model(pruned_model)
      tflite_model = converter.convert()
  
      tflite_model_path = "/tmp/mnist_2x4.tflite"
      print("model is saved to {}".format(tflite_model_path))
      with open(tflite_model_path, "wb") as f:
          f.write(tflite_model)
  
      print("evaluate pruned model: ")
      print(
          keras_test_utils.eval_mnist_tflite(model_content=tflite_model)
      )
  
file_path: model-optimization/tensorflow_model_optimization/python/examples/sparsity/keras/mnist/mnist_e2e_sparsity2x4.py
imports: from __future__ import print_function
  from absl import app
  import tensorflow
  from tensorflow_model_optimization.python.core.keras import test_utils
  from tensorflow_model_optimization.python.core.sparsity.keras import prune
  from tensorflow_model_optimization.python.core.sparsity.keras import pruning_callbacks
  from tensorflow_model_optimization.python.core.sparsity.keras import pruning_schedule
  from tensorflow_model_optimization.python.core.sparsity.keras import pruning_utils
  from tensorflow_model_optimization.python.core.sparsity.keras import pruning_wrapper
label_desc: Use image node_id 4 for calling a global function with example usage: main(unused_argv) without return types