code: def evaluate_and_show_sparsity(model, image_test, label_test):
      score = model.evaluate(image_test, label_test, verbose=0)
      print("Test loss:", score[0])
      print("Test accuracy:", score[1])
  
      for layer in model.layers:
          if isinstance(
              layer, prune.pruning_wrapper.PruneLowMagnitude
          ) or isinstance(
              layer, quantize.quantize_wrapper.QuantizeWrapper
          ):
              for weights in layer.trainable_weights:
                  np_weights = tf.keras.backend.get_value(weights)
                  sparsity = 1.0 - np.count_nonzero(np_weights) / float(
                      np_weights.size
                  )
                  print(
                      layer.layer.__class__.__name__,
                      " (",
                      weights.name,
                      ") sparsity: ",
                      sparsity,
                  )
  
file_path: model-optimization/tensorflow_model_optimization/python/examples/quantization_with_sparsity/keras/mnist_cnn.py
imports: from __future__ import print_function
  from absl import app
  import numpy
  import tensorflow
  from tensorflow_model_optimization.python.core.quantization.keras import quantize
  from tensorflow_model_optimization.python.core.quantization.keras.collab_opts.prune_preserve import default_8bit_prune_preserve_quantize_scheme
  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
label_desc: Use image node_id 3 for calling a global function with example usage: evaluate_and_show_sparsity(model, image_test, label_test) without return types