code: def calc_masks(self, sparsity, wrapper, wrapper_idx=None):
      masks = {}
      for weight_variable in wrapper.layer.weights:
          if "bias" in weight_variable.name:
              continue
  
          num_prune = int(tf.size(weight_variable).numpy() * sparsity)
          if num_prune == 0:
              continue
  
          weight = weight_variable.read_value()
          if wrapper.masks.get(weight_variable.name) is not None:
              weight = tf.math.multiply(
                  weight, wrapper.masks[weight_variable.name]
              )
  
          w_abs = tf.math.abs(weight)
          k = tf.size(weight) - num_prune
          topk = tf.math.top_k(tf.reshape(w_abs, [-1]), k)[0]
          if tf.size(topk) == 0:
              mask = tf.zeros_like(weight)
          else:
              mask = tf.math.greater_equal(w_abs, topk[-1])
          masks[weight_variable.name] = tf.cast(mask, weight.dtype)
      return masks
  
file_path: auptimizer/src/aup/compression/tensorflow/pruning/one_shot.py
imports: import tensorflow
  from ..compressor import Pruner
label_desc: Use image node_id 1 for calling the LevelPrunerMasker obj's underlying member method code with example usage: obj.calc_masks(sparsity, wrapper, wrapper_idx) and returns: masks