code: def test_quantized_bn():
      def get_mean_var(data):
          axes = list(range(data.ndim))
          del axes[1]
          mean = mx.np.mean(data, axis=axes)
          mean_broad = mx.np.expand_dims(mean, axis=0)
          mean_broad = mx.np.expand_dims(mean_broad, axis=2)
          mean_broad = mx.np.expand_dims(mean_broad, axis=3)
          mean_broad = mx.npx.broadcast_like(mean_broad, data)
          var = mx.np.multiply(data - mean_broad, data - mean_broad)
          axes = list(range(var.ndim))
          del axes[1]
          var = mx.np.mean(var, axis=axes)
          return mean, var
  
      def check_quantized_bn(data_shape, qdtype):
          if is_test_for_native_cpu():
              print(
                  "skipped testing quantize_bn for native cpu since it is not supported yet"
              )
              return
          elif is_test_for_gpu():
              print(
                  "skipped testing quantize_bn for gpu since it is not supported yet"
              )
              return
  
          data_low, data_high = get_low_high(qdtype)
  
          # run fp32 bn
          bn_fp32 = mx.gluon.nn.BatchNorm(
              use_global_stats=True, scale=True
          )
          data = mx.np.random.uniform(
              low=data_low, high=data_high, size=data_shape
          )
          bn_fp32.initialize()
          bn_fp32.hybridize()
          bn_fp32(data)
          fp32_params = bn_fp32.collect_params()
  
          data = mx.np.random.uniform(
              low=data_low, high=data_high, size=data_shape
          )
          gamma = mx.np.random.uniform(
              low=data_low,
              high=data_high,
              size=fp32_params["gamma"].shape,
          )
          beta = mx.np.random.uniform(
              low=data_low,
              high=data_high,
              size=fp32_params["beta"].shape,
          )
          running_mean, running_var = get_mean_var(data)
          new_params = {
              "gamma": gamma,
              "beta": beta,
              "running_mean": running_mean,
              "running_var": running_var,
          }
  
          bn_fp32.load_dict(new_params)
          output = bn_fp32(data)
  
          # generate int8 bn from fp32 bn
          calib_data = mx.gluon.data.DataLoader(
              data, batch_size=data_shape[0]
          )
          quant_bn = mx.contrib.quant.quantize_net(
              bn_fp32,
              quantized_dtype=qdtype,
              quantize_mode="full",
              calib_data=calib_data,
              calib_mode="naive",
              num_calib_batches=1,
              device=mx.current_device(),
          )
  
          output_int8_to_fp32 = quant_bn(data)
  
          assert_almost_equal(
              output.asnumpy(),
              output_int8_to_fp32.asnumpy(),
              rtol=1e-1,
              atol=8,
          )
  
      for qdtype in ["int8", "uint8"]:
          check_quantized_bn((32, 512, 4, 4), qdtype)
          check_quantized_bn((32, 1024, 8, 8), qdtype)
          check_quantized_bn((32, 3, 224, 224), qdtype)
  
imports: import os
  import mxnet
  import numpy
  from mxnet import npx
  from mxnet.util import use_np
  from mxnet.gluon.model_zoo import vision
  from mxnet.test_utils import assert_almost_equal, assert_exception, rand_ndarray, rand_shape_nd, same, DummyIter
  from common import xfail_when_nonstandard_decimal_separator
  from mxnet.io import NDArrayIter
  import unittest
  import operator
label_desc: Use image node_id 20 for calling a global function with example usage: test_quantized_bn() and returns: mean,  var