class_docstr: A structured pruning algorithm that prunes channels by pruning the weights of BN layers.
  Zhuang Liu, Jianguo Li, Zhiqiang Shen, Gao Huang, Shoumeng Yan and Changshui Zhang
  "Learning Efficient Convolutional Networks through Network Slimming", 2017 ICCV
  https://arxiv.org/pdf/1708.06519.pdf
class_docstr_tok: ["A","structured","pruning","algorithm","that","prunes","channels","by","pruning","the","weights","of","BN","layers",".","Zhuang","Liu",",","Jianguo","Li",",","Zhiqiang","Shen",",","Gao","Huang",",","Shoumeng","Yan","and","Changshui","Zhang","''","Learning","Efficient","Convolutional","Networks","through","Network","Slimming","''",",","2017","ICCV","https",":","\/\/arxiv.org\/pdf\/1708.06519.pdf"]
code: def calc_mask(self, sparsity, wrapper, wrapper_idx=None):
      assert (
          wrapper.type == "BatchNorm2d"
      ), "SlimPruner only supports 2d batch normalization layer pruning"
      weight = wrapper.module.weight.data.clone()
      if wrapper.weight_mask is not None:
          # apply base mask for iterative pruning
          weight = weight * wrapper.weight_mask
  
      base_mask = torch.ones(weight.size()).type_as(weight).detach()
      mask = {
          "weight_mask": base_mask.detach(),
          "bias_mask": base_mask.clone().detach(),
      }
      filters = weight.size(0)
      num_prune = int(filters * sparsity)
      if filters >= 2 and num_prune >= 1:
          w_abs = weight.abs()
          mask_weight = torch.gt(w_abs, self.global_threshold).type_as(
              weight
          )
          mask_bias = mask_weight.clone()
          mask = {
              "weight_mask": mask_weight.detach(),
              "bias_mask": mask_bias.detach(),
          }
      return mask
  
imports: import logging
  import math
  import numpy
  import torch
  from .weight_masker import WeightMasker
label_desc: Use image node_id 2 for calling the SlimPrunerMasker obj's underlying member method code with example usage: obj.calc_mask(sparsity, wrapper, wrapper_idx) and returns: mask