code: def convert(model_file, output_dir, layers):
      mace_check(
          os.path.isdir(output_dir),
          "Output directory '" + output_dir + "' does not exist!",
      )
      multi_net_def = init_multi_net_def(model_file)
      multi_net_info = MultiNetDefInfo(multi_net_def, layers)
  
      output_configs = {ModelKeys.subgraphs: []}
      while multi_net_info.index_valid():
          # omit BatchToSpaceND and op before that due to changed graph
          cur_op = multi_net_info.get_current_op()
          next_op = multi_net_info.get_next_op()
          if (
              cur_op.type == MaceOp.BatchToSpaceND.name
              or cur_op.type == HexagonOp.BatchToSpaceND_8.name
              or (
                  cur_op.type == MaceOp.Quantize.name
                  or cur_op.type == HexagonOp.QuantizeINPUT_f_to_8.name
                  or cur_op.type == HexagonOp.INPUT.name
              )
              or (
                  cur_op.type == MaceOp.Dequantize.name
                  or cur_op.type == HexagonOp.DequantizeOUTPUT_8tof.name
                  or cur_op.type == HexagonOp.OUTPUT.name
              )
              or (
                  next_op is not None
                  and (
                      next_op.type == MaceOp.BatchToSpaceND.name
                      or next_op.type == HexagonOp.BatchToSpaceND_8.name
                  )
              )
              or cur_op.name.startswith(
                  MaceKeyword.mace_output_node_name
              )
          ):
              multi_net_info.StartIndexIncrement()
              continue
          multi_net = copy.deepcopy(multi_net_def)
          net_defs = multi_net.net_def
  
          # remove unused net_def
          net = None
          cur_net_idx = multi_net_info.get_current_net_idx()
          for net_def in net_defs[:]:
              if net_def.infer_order == cur_net_idx:
                  net = net_def
              elif net_def.infer_order > cur_net_idx:
                  net_defs.remove(net_def)
          del multi_net.output_tensor[:]
  
          # remove unsued op
          cur_op_idx = multi_net_info.get_current_op_idx()
          is_hexagon = multi_net_info.is_hexagon(cur_net_idx)
          if is_hexagon:
              # reuse dequantize op and it's min/max tensor's node_id
              del net.op[(cur_op_idx + 1) : -1]
          else:
              del net.op[(cur_op_idx + 1) :]
          del net.output_info[:]
          op = net.op[cur_op_idx]
          multi_net_info.StartIndexIncrement()
  
          output_tensors = []
          output_shapes = []
          output_data_types = []
          output_data_formats = []
          op_name = op.name
          if str(op.name).startswith(MaceKeyword.mace_output_node_name):
              continue
          is_quantize = multi_net_info.is_quantize(cur_net_idx)
          if is_quantize:
              op.name = (
                  MaceKeyword.mace_output_node_name + "_" + op.name
              )
          if is_hexagon:
              if len(op.output) != 1:
                  print("Skip %s(%s)" % (op.name, op.type))
                  continue
          data_format = ConverterUtil.get_arg(
              op, MaceKeyword.mace_data_format_str
          )
          for i in range(len(op.output)):
              output_tensors.append(str(op.output[i]))
              output_shapes.append(
                  ",".join(
                      [str(dim) for dim in op.output_shape[i].dims]
                  )
              )
              if data_format.i == DataFormat.NONE.value:
                  output_data_formats.append(DataFormat.NONE.name)
              elif data_format.i == DataFormat.NCHW.value:
                  output_data_formats.append(DataFormat.NCHW.name)
              else:
                  output_data_formats.append(DataFormat.NHWC.name)
              # modify output info
              multi_net.output_tensor.append(op.output[i])
              output_info = net.output_info.add()
              output_info.name = op.output[i]
              output_info.data_format = data_format.i
              output_info.dims.extend(op.output_shape[i].dims)
              data_type = ConverterUtil.get_arg(
                  op, MaceKeyword.mace_op_data_type_str
              )
              if mace_pb2.DT_INT32 == data_type.i:
                  output_info.data_type = mace_pb2.DT_INT32
                  output_data_types.append("int32")
              else:
                  output_info.data_type = mace_pb2.DT_FLOAT
                  output_data_types.append("float32")
              if is_quantize:
                  output_info.scale = op.quantize_info[0].scale
                  output_info.zero_point = op.quantize_info[
                      0
                  ].zero_point
              # modify output op
              if is_quantize:
                  output_name = op.output[i]
                  new_output_name = (
                      MaceKeyword.mace_output_node_name
                      + "_"
                      + op.output[i]
                  )
                  op.output[i] = new_output_name
                  if not is_hexagon:
                      dequantize_op = net.op.add()
                      dequantize_op.name = normalize_op_name(
                          output_name
                      )
                      dequantize_op.type = MaceOp.Dequantize.name
                      dequantize_op.input.append(new_output_name)
                      dequantize_op.output.append(output_name)
                      output_shape = dequantize_op.output_shape.add()
                      output_shape.dims.extend(op.output_shape[i].dims)
                      dequantize_op.output_type.append(
                          mace_pb2.DT_FLOAT
                      )
                      ConverterUtil.add_data_type_arg(
                          dequantize_op, mace_pb2.DT_UINT8
                      )
                  else:
                      dequantize_op = net.op[-1]
                      dequantize_op.name = normalize_op_name(
                          output_name
                      )
                      del dequantize_op.input[:]
                      del dequantize_op.output[:]
                      dequantize_op.input.append(new_output_name)
                      dequantize_op.node_input[0].node_id = op.node_id
                      dequantize_op.output.append(output_name)
                      if (
                          dequantize_op.type
                          == HexagonOp.DequantizeOUTPUT_8tof.name
                      ):
                          input_min = new_output_name[:-1] + "1"
                          input_max = new_output_name[:-1] + "2"
                          dequantize_op.input.extend(
                              [input_min, input_max]
                          )
                          dequantize_op.node_input[
                              1
                          ].node_id = op.node_id
                          dequantize_op.node_input[
                              2
                          ].node_id = op.node_id
                          del dequantize_op.node_input[3:]
                      else:
                          del dequantize_op.node_input[1:]
  
          model_path = save_model_to_proto(
              multi_net, normalize_op_name(op_name), output_dir
          )
          output_config = {
              ModelKeys.model_file_path: str(model_path),
              ModelKeys.output_tensors: output_tensors,
              ModelKeys.output_shapes: output_shapes,
              "output_data_formats": output_data_formats,
              ModelKeys.output_data_types: output_data_types,
          }
          output_configs[ModelKeys.subgraphs].append(output_config)
  
      output_configs_path = output_dir + "outputs.yml"
      with open(output_configs_path, "w") as f:
          yaml.dump(output_configs, f, default_flow_style=False)
  
imports: import argparse
  import copy
  import os
  import sh
  import yaml
  from py_proto import mace_pb2
  from transform.base_converter import ConverterUtil
  from transform.base_converter import MaceKeyword
  from transform.base_converter import MaceOp
  from transform.hexagon_converter import HexagonOp
  from utils.config_parser import DataFormat
  from utils.config_parser import ModelKeys
  from utils.util import mace_check
label_desc: Use image node_id 4 for calling a global function with example usage: convert(model_file, output_dir, layers) without return types