class_docstr: A Keras callback for adding pruning summaries to tensorboard.
  
  Logs the sparsity(%) and threshold at a given iteration step.
class_docstr_tok: ["A","Keras","callback","for","adding","pruning","summaries","to","tensorboard",".","Logs","the","sparsity","(","%",")","and","threshold","at","a","given","iteration","step","."]
code: def on_epoch_begin(self, epoch, logs=None):
      if logs is not None:
          super(PruningSummaries, self).on_epoch_begin(epoch, logs)
  
      pruning_logs = {}
      params = []
      prunable_layers = pruning_wrapper.collect_prunable_layers(
          self.model
      )
      for layer in prunable_layers:
          for _, mask, threshold in layer.pruning_vars:
              params.append(mask)
              params.append(threshold)
  
      params.append(self.model.optimizer.iterations)
  
      values = K.batch_get_value(params)
      iteration = values[-1]
      del values[-1]
      del params[-1]
  
      param_value_pairs = list(zip(params, values))
  
      for mask, mask_value in param_value_pairs[::2]:
          pruning_logs.update(
              {mask.name + "/sparsity": 1 - np.mean(mask_value)}
          )
  
      for threshold, threshold_value in param_value_pairs[1::2]:
          pruning_logs.update(
              {threshold.name + "/threshold": threshold_value}
          )
  
      self._log_pruning_metrics(pruning_logs, "", iteration)
  
file_path: model-optimization/tensorflow_model_optimization/python/core/sparsity/keras/pruning_callbacks.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import numpy
  import six
  import tensorflow
  from tensorflow_model_optimization.python.core.keras import compat
  from tensorflow_model_optimization.python.core.sparsity.keras import pruning_wrapper
label_desc: Use image node_id 3 for calling the PruningSummaries obj's underlying member method code with example usage: obj.on_epoch_begin(epoch, logs) without return types