code: def convert_ops(self):
      print("Convert mace graph to apu.")
      for op in self._model.op:
          if not self._apu_ops.has_op(op.type):
              raise Exception("Unsupported op: ", op)
          if (
              op.type == MaceOp.Conv2D.name
              or op.type == MaceOp.DepthwiseConv2d.name
          ):
              mace_check(
                  len(op.input) == 3,
                  op.name + ": apu only support " + op.type + " op"
                  " with 3 input",
              )
              self.add_size_tensor_from_arg(
                  op, MaceKeyword.mace_strides_str
              )
              self.add_padding_value_tensor_from_arg(op)
              self.add_size_tensor_from_arg(
                  op, MaceKeyword.mace_dilations_str
              )
              if op.type == MaceOp.DepthwiseConv2d.name:
                  multiplier = self._model.tensors.add()
                  multiplier.name = op.name + "/multiplier:0"
                  multiplier.data_type = mace_pb2.DT_INT32
                  multiplier.dims.extend([1])
                  for tensor in self._model.tensors:
                      if tensor.name == op.input[1]:
                          multiplier.int32_data.extend([tensor.dims[0]])
                          break
                  op.input.extend([multiplier.name])
          elif op.type == MaceOp.Deconv2D.name:
              mace_check(
                  len(op.input) == 4,
                  op.name + ": apu only support " + op.type + " op"
                  " with 4 input",
              )
              self.add_size_tensor_from_arg(
                  op, MaceKeyword.mace_strides_str
              )
              self.add_padding_value_tensor_from_arg(op)
              self.add_size_tensor_from_list(
                  op, MaceKeyword.mace_dilations_str, [1, 1]
              )
          elif op.type == MaceOp.Eltwise.name:
              eltwise_type = ConverterUtil.get_arg(
                  op, MaceKeyword.mace_element_type_str
              ).i
              # We only handle SUM and PROD operators now which are
              # commutative
              mace_check(
                  len(op.input) == 2,
                  op.name + ": apu only support eltwise op with 2"
                  " input",
              )
              mace_check(
                  eltwise_type == EltwiseType.SUM.value
                  or eltwise_type == EltwiseType.PROD.value,
                  op.name
                  + ": apu only support eltwise type SUM or PROD",
              )
          elif op.type == MaceOp.Pad.name:
              mace_check(
                  len(op.input) == 1,
                  op.name + ": apu only support Pad op with 1" " input",
              )
              pad_type_arg = ConverterUtil.get_arg(
                  op, MaceKeyword.mace_pad_type_str
              )
              if pad_type_arg is not None:
                  mace_check(
                      PadType(pad_type_arg.i) == PadType.CONSTANT,
                      op.name + ": apu only support Pad type CONSTANT",
                  )
  
              padding_arg = ConverterUtil.get_arg(
                  op, MaceKeyword.mace_paddings_str
              )
              mace_check(
                  len(padding_arg.ints) == 8,
                  op.name + ": paddings does not have size 8",
              )
              mace_check(
                  {0}
                  == {
                      padding_arg.ints[0],
                      padding_arg.ints[1],
                      padding_arg.ints[6],
                      padding_arg.ints[7],
                  },
                  op.name + ": apu only support Pad op with padding"
                  " in H/W dimensions",
              )
              data_type = ConverterUtil.get_arg(op, "T").i
              constant_value_arg = ConverterUtil.get_arg(
                  op, MaceKeyword.mace_constant_value_str
              )
              if constant_value_arg is not None:
                  if data_type in [mace_pb2.DT_FLOAT, mace_pb2.DT_HALF]:
                      constant_value = constant_value_arg.f
                  elif data_type == mace_pb2.DT_INT32:
                      constant_value = constant_value_arg.i
                  else:
                      mace_check(False, "Not supported data type")
  
                  mace_check(
                      constant_value == 0,
                      op.name + ": apu only support Pad op with zero"
                      " padding",
                  )
              self.add_paddings_tensor_from_arg(op)
  
          elif op.type == MaceOp.Pooling.name:
              mace_check(
                  len(op.input) == 1,
                  op.name + ": apu only support pooling op with 1"
                  " input",
              )
              pooling_type_arg = ConverterUtil.get_arg(
                  op, MaceKeyword.mace_pooling_type_str
              )
              mace_check(
                  PoolingType(pooling_type_arg.i)
                  in [PoolingType.AVG, PoolingType.MAX],
                  op.name + ": apu only support pooling type AVG,"
                  " MAX",
              )
              self.add_padding_value_tensor_from_arg(op)
              self.add_size_tensor_from_arg(
                  op, MaceKeyword.mace_strides_str
              )
              self.add_size_tensor_from_arg(
                  op, MaceKeyword.mace_kernel_str
              )
          elif op.type == MaceOp.Concat.name:
              self.add_int_tensor_from_arg(
                  op, MaceKeyword.mace_axis_str
              )
          elif op.type == MaceOp.Reduce.name:
              mace_check(
                  len(op.input) == 1,
                  op.name + ": apu only support reduce op with 1"
                  " input",
              )
              self.add_int_list_tensor_from_arg(
                  op, MaceKeyword.mace_axis_str
              )
              self.add_int_tensor_from_arg(
                  op, MaceKeyword.mace_keepdims_str
              )
          elif op.type == MaceOp.ResizeBilinear.name:
              mace_check(
                  len(op.input) == 1,
                  op.name + ": apu only support resize bilinear op"
                  " with 1 input",
              )
              self.add_int_tensor_from_arg(
                  op, MaceKeyword.mace_align_corners_str
              )
          elif op.type == MaceOp.Reshape.name:
              mace_check(
                  len(op.input) == 1 or len(op.input) == 2,
                  op.name + ": apu only support reshape op with 1 or"
                  " 2 input",
              )
          elif op.type == MaceOp.Softmax.name:
              mace_check(
                  len(op.input) == 1,
                  op.name + ": apu only support softmax op with 1"
                  " input",
              )
              beta_value_tensor = self._model.tensors.add()
              beta_value_tensor.name = op.name + "/beta:0"
              beta_value_tensor.data_type = mace_pb2.DT_FLOAT
              beta_value_tensor.dims.extend([1])
              beta_value_tensor.float_data.extend([1.0])
              op.input.extend([beta_value_tensor.name])
          elif op.type == MaceOp.Squeeze.name:
              mace_check(
                  len(op.input) == 1,
                  op.name + ": apu only support squeeze op with 1"
                  " input",
              )
              self.add_shape_tensor_from_axis_arg(op)
          elif op.type == MaceOp.DepthToSpace.name:
              mace_check(
                  len(op.input) == 1,
                  op.name + ": apu only support DepthToSpace op with"
                  " 1 input",
              )
          elif op.type == MaceOp.SpaceToDepth.name:
              mace_check(
                  len(op.input) == 1,
                  op.name + ": apu only support SpaceToDepth op with"
                  " 1 input",
              )
          op.type = self._apu_ops.map_nn_op(op.type)
      self.change_activation_to_prelu()
  
imports: import copy
  import numpy
  from enum import Enum
  from operator import mul
  from py_proto import mace_pb2
  from transform import base_converter
  from transform.base_converter import ConverterUtil
  from transform.base_converter import EltwiseType
  from transform.base_converter import MaceKeyword
  from transform.base_converter import MaceOp
  from transform.base_converter import PaddingMode
  from transform.base_converter import PadType
  from transform.base_converter import PoolingType
  from transform.base_converter import ReduceType
  from transform.base_converter import DataFormat
  from transform.base_converter import FrameworkType
  from utils.util import mace_check
label_desc: Use image node_id 4 for calling the ApuConverter obj's underlying member method code with example usage: obj.convert_ops() without return types