class_docstr: A class for convert megengine dumped model to mace model.
class_docstr_tok: ["A","class","for","convert","megengine","dumped","model","to","mace","model","."]
code: def convert_batchnorm(self, mge_op):
      op = self.convert_general_op(mge_op)
      op.type = MaceOp.BatchNorm.name
  
      gamma_value = get_symvar_value(
          self._bn_statistis_tensors[mge_op.inputs[1].name]
      ).flatten()
      beta_value = get_symvar_value(
          self._bn_statistis_tensors[mge_op.inputs[2].name]
      ).flatten()
      mean_value = get_symvar_value(mge_op.inputs[3]).flatten()
      var_value = get_symvar_value(mge_op.inputs[4]).flatten()
      epsilon_value = 1e-5
  
      scale_name = mge_op.name + "_scale"
      offset_name = mge_op.name + "_offset"
      scale_value = (
          1.0 / np.vectorize(math.sqrt)(var_value + epsilon_value)
      ) * gamma_value
      offset_value = (-mean_value * scale_value) + beta_value
      self.add_tensor(
          scale_name, scale_value.shape, mace_pb2.DT_FLOAT, scale_value
      )
      self.add_tensor(
          offset_name,
          offset_value.shape,
          mace_pb2.DT_FLOAT,
          offset_value,
      )
      self._skip_tensors.update([inp.name for inp in mge_op.inputs][1:])
  
      del op.input[1:]
      op.input.extend([scale_name, offset_name])
      # outputs[4] is the correct output
      del op.output[-1:]
      del op.output_shape[-1:]
      del op.output[:4]
      del op.output_shape[:4]
  
imports: import os
  import math
  import numpy
  import six
  import megengine._internal
  from enum import Enum
  from py_proto import mace_pb2
  from transform import base_converter
  from transform.base_converter import PoolingType
  from transform.base_converter import ActivationType
  from transform.base_converter import EltwiseType
  from transform.base_converter import FrameworkType
  from transform.base_converter import ReduceType
  from transform.base_converter import DataFormat
  from transform.base_converter import MaceOp
  from transform.base_converter import MaceKeyword
  from transform.base_converter import ConverterUtil
  from transform.base_converter import RoundMode
  from utils.util import mace_check
label_desc: Use image node_id 23 for calling the MegengineConverter obj's underlying member method code with example usage: obj.convert_batchnorm(mge_op) without return types