code: def prune_gluon_block(
      net,
      prefix,
      params_shapes,
      params=None,
      pretrained=False,
      ctx=cpu(0),
  ):
      """
      :param params_shapes: dictionary of shapes of convolutional weights
      :param prefix: prefix of the original resnet50_v1d
      :param pretrained: Boolean specifying if the pretrained model parameters needs to be loaded
      :param net: original network that is required to be pruned
      :param params: dictionary of parameters for the pruned network. Size of the parameters in
      this dictionary tells what
      should be the size of channels of each convolution layer.
      :param ctx: cpu(0)
      :return: "net"
      """
      for _, layer in net._children.items():
          if isinstance(layer, nn.BatchNorm):
              params_layer = layer._collect_params_with_prefix()
              for param_name in [
                  "beta",
                  "gamma",
                  "running_mean",
                  "running_var",
              ]:
                  if pretrained:
                      param_val = params[
                          layer.name.replace(prefix, "resnetv1d")
                          + "_"
                          + param_name
                      ]
                      layer.params.get(
                          param_name
                      )._shape = param_val.shape
                      params_layer[param_name]._load_init(
                          param_val, ctx=ctx
                      )
                  else:
                      layer.params.get(param_name)._shape = None
                      layer.params.get(param_name).initialize(
                          ctx=ctx, force_reinit=True
                      )
  
          if isinstance(layer, nn.Conv2D):
              param_shape = params_shapes[
                  layer.name.replace(prefix, "resnetv1d") + "_weight"
              ]
              layer._channels = param_shape[0]
              layer._kwargs["num_filter"] = param_shape[0]
  
              params_layer = layer._collect_params_with_prefix()
              for param_name in ["weight"]:
                  param_shape = params_shapes[
                      layer.name.replace(prefix, "resnetv1d")
                      + "_"
                      + param_name
                  ]
                  layer.params.get(param_name)._shape = param_shape
                  if pretrained:
                      param_val = params[
                          layer.name.replace(prefix, "resnetv1d")
                          + "_"
                          + param_name
                      ]
                      params_layer[param_name]._load_init(
                          param_val, ctx=ctx
                      )
  
          if isinstance(layer, nn.Dense):
              layer._in_units = params_shapes[
                  layer.name.replace(prefix, "resnetv1d") + "_weight"
              ][1]
  
              params_layer = layer._collect_params_with_prefix()
              for param_name in ["weight", "bias"]:
                  param_shape = params_shapes[
                      layer.name.replace(prefix, "resnetv1d")
                      + "_"
                      + param_name
                  ]
                  layer.params.get(param_name)._shape = param_shape
                  if pretrained:
                      param_val = params[
                          layer.name.replace(prefix, "resnetv1d")
                          + "_"
                          + param_name
                      ]
                      params_layer[param_name]._load_init(
                          param_val, ctx=ctx
                      )
          else:
              prune_gluon_block(
                  layer, prefix, params_shapes, params, pretrained, ctx
              )
  
file_path: gluon-cv/gluoncv/model_zoo/pruned_resnet/resnetv1b_pruned.py
imports: from __future__ import division
  import json
  import os
  from mxnet.context import cpu
  from mxnet.gluon import nn
  from mxnet import ndarray
  from ..resnetv1b import ResNetV1b
  from ..resnetv1b import BasicBlockV1b
  from ..resnetv1b import BottleneckV1b
label_desc: Use image node_id 1 for calling a global function with example usage: prune_gluon_block(net, prefix, params_shapes, params, pretrained, ctx) without return types