(model_file, output_dir, layers)
| 166 | |
| 167 | |
| 168 | def convert(model_file, output_dir, layers): |
| 169 | mace_check(os.path.isdir(output_dir), |
| 170 | "Output directory '" + output_dir + "' does not exist!") |
| 171 | multi_net_def = init_multi_net_def(model_file) |
| 172 | multi_net_info = MultiNetDefInfo(multi_net_def, layers) |
| 173 | |
| 174 | output_configs = {ModelKeys.subgraphs: []} |
| 175 | while multi_net_info.index_valid(): |
| 176 | # omit BatchToSpaceND and op before that due to changed graph |
| 177 | cur_op = multi_net_info.get_current_op() |
| 178 | next_op = multi_net_info.get_next_op() |
| 179 | if cur_op.type == MaceOp.BatchToSpaceND.name or \ |
| 180 | cur_op.type == HexagonOp.BatchToSpaceND_8.name or \ |
| 181 | (cur_op.type == MaceOp.Quantize.name or |
| 182 | cur_op.type == HexagonOp.QuantizeINPUT_f_to_8.name or |
| 183 | cur_op.type == HexagonOp.INPUT.name) or \ |
| 184 | (cur_op.type == MaceOp.Dequantize.name or |
| 185 | cur_op.type == HexagonOp.DequantizeOUTPUT_8tof.name or |
| 186 | cur_op.type == HexagonOp.OUTPUT.name) or \ |
| 187 | (next_op is not None and |
| 188 | (next_op.type == MaceOp.BatchToSpaceND.name or |
| 189 | next_op.type == HexagonOp.BatchToSpaceND_8.name)) or \ |
| 190 | cur_op.name.startswith(MaceKeyword.mace_output_node_name): |
| 191 | multi_net_info.StartIndexIncrement() |
| 192 | continue |
| 193 | multi_net = copy.deepcopy(multi_net_def) |
| 194 | net_defs = multi_net.net_def |
| 195 | |
| 196 | # remove unused net_def |
| 197 | net = None |
| 198 | cur_net_idx = multi_net_info.get_current_net_idx() |
| 199 | for net_def in net_defs[:]: |
| 200 | if net_def.infer_order == cur_net_idx: |
| 201 | net = net_def |
| 202 | elif net_def.infer_order > cur_net_idx: |
| 203 | net_defs.remove(net_def) |
| 204 | del multi_net.output_tensor[:] |
| 205 | data_format = net.output_info[0].data_format |
| 206 | |
| 207 | # remove unsued op |
| 208 | cur_op_idx = multi_net_info.get_current_op_idx() |
| 209 | is_hexagon = multi_net_info.is_hexagon(cur_net_idx) |
| 210 | if is_hexagon: |
| 211 | # reuse dequantize op and it's min/max tensor's node_id |
| 212 | del net.op[(cur_op_idx + 1):-1] |
| 213 | else: |
| 214 | del net.op[(cur_op_idx + 1):] |
| 215 | del net.output_info[:] |
| 216 | op = net.op[cur_op_idx] |
| 217 | multi_net_info.StartIndexIncrement() |
| 218 | |
| 219 | output_tensors = [] |
| 220 | output_shapes = [] |
| 221 | output_data_types = [] |
| 222 | output_data_formats = [] |
| 223 | op_name = op.name |
| 224 | if str(op.name).startswith(MaceKeyword.mace_output_node_name): |
| 225 | continue |
no test coverage detected