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_subtensor(self, mge_op):
      op1 = self.convert_general_op(mge_op)
      op1.type = MaceOp.StridedSlice.name
  
      axis = mge_op.inputs[1].inferred_value
      t_shape = list(mge_op.inputs[0].imm_shape)
  
      begin_tensor_name = mge_op.name + "_begin"
      end_tensor_name = mge_op.name + "_end"
      stride_tensor_name = mge_op.name + "_stride"
      begin_tensor_shape = (len(t_shape),)
      end_tensor_shape = (len(t_shape),)
      stride_tensor_shape = (len(t_shape),)
  
      begin_vals = [0] * len(t_shape)
      end_vals = [shapei for shapei in t_shape]
      stride_vals = [1] * len(t_shape)
  
      def check_val(sym_var):
          try:
              val = sym_var.inferred_value[0]
          except TypeError:
              mace_check(
                  False,
                  "you should feed const values for subtensor axis",
              )
          return val
  
      squeeze_dims = []
      idx = len(mge_op.inputs) - 1
      while idx:
          val = check_val(mge_op.inputs[idx])
          for ai in mge_op.params[::-1]:
              ai_idx = ai["axis"]
              if ai["step"] > 0:
                  stride_vals[ai_idx] = val
                  idx -= 1
                  if idx == 0:
                      break
                  val = check_val(mge_op.inputs[idx])
              if ai["end"] > 0:
                  if val < 0:
                      val = t_shape[ai_idx] + val
                  end_vals[ai_idx] = val
                  idx -= 1
                  if idx == 0:
                      break
                  val = check_val(mge_op.inputs[idx])
              if ai["begin"] > 0:
                  if val < 0:
                      val = t_shape[ai_idx] + val
                  begin_vals[ai_idx] = val
                  idx -= 1
                  if idx == 0:
                      break
                  val = check_val(mge_op.inputs[idx])
              if ai["idx"] > 0:
                  if val < 0:
                      val = t_shape[ai_idx] + val
                  squeeze_dims.append(ai_idx)
                  begin_vals[ai_idx] = val
                  end_vals[ai_idx] = val + 1
                  idx -= 1
                  if idx == 0:
                      break
                  val = check_val(mge_op.inputs[idx])
  
      for ai_idx in range(len(t_shape)):
          t_shape[ai_idx] = math.ceil(
              (end_vals[ai_idx] - begin_vals[ai_idx])
              / stride_vals[ai_idx]
          )
  
      self.add_tensor(
          begin_tensor_name,
          begin_tensor_shape,
          mace_pb2.DT_INT32,
          begin_vals,
      )
      self.add_tensor(
          end_tensor_name, end_tensor_shape, mace_pb2.DT_INT32, end_vals
      )
      self.add_tensor(
          stride_tensor_name,
          stride_tensor_shape,
          mace_pb2.DT_INT32,
          stride_vals,
      )
  
      del op1.input[1:]
      op1.input.extend(
          [begin_tensor_name, end_tensor_name, stride_tensor_name]
      )
  
      if len(squeeze_dims) > 0:
          # create squeeze op to remove shape=1 dims
          mid_output_name = mge_op.name + "_mid_reshape"
  
          del op1.output[0]
          op1.output.extend([mid_output_name])
          output_shape = op1.output_shape[0]
          del output_shape.dims[:]
          output_shape.dims.extend(t_shape)
  
          op2 = self._mace_net_def.op.add()
          op2.type = MaceOp.Squeeze.name
          op2.name = mge_op.name + "_squeeze"
  
          data_type_arg = op2.arg.add()
          data_type_arg.name = "T"
          data_type_arg.i = self._option.data_type
  
          framework_type_arg = op2.arg.add()
          framework_type_arg.name = MaceKeyword.mace_framework_type_str
          framework_type_arg.i = FrameworkType.MEGENGINE.value
  
          ConverterUtil.add_data_format_arg(op2, DataFormat.NCHW)
  
          op2.input.extend([mid_output_name])
          op2.output.extend([mge_op.outputs[0].name])
          output_shape = op2.output_shape.add()
          output_shape.dims.extend(mge_op.outputs[0].imm_shape)
  
          axis_arg = op2.arg.add()
          axis_arg.name = MaceKeyword.mace_axis_str
          axis_arg.ints.extend(squeeze_dims)
  
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 25 for calling the MegengineConverter obj's underlying member method code with example usage: obj.convert_subtensor(mge_op) and returns: val