(conf, output, enable_micro=False)
| 68 | |
| 69 | |
| 70 | def convert(conf, output, enable_micro=False): |
| 71 | for model_name, model_conf in conf["models"].items(): |
| 72 | model_output = output + "/" + model_name + "/model" |
| 73 | org_model_dir = output + "/" + model_name + "/org_model" |
| 74 | util.mkdir_p(model_output) |
| 75 | util.mkdir_p(org_model_dir) |
| 76 | |
| 77 | model_conf = normalize_model_config(model_conf, model_output, |
| 78 | org_model_dir) |
| 79 | conf["models"][model_name] = model_conf |
| 80 | net_confs = model_conf[ModelKeys.subgraphs] |
| 81 | |
| 82 | model = mace_pb2.MultiNetDef() |
| 83 | add_input_output_tensor(model, model_conf) |
| 84 | |
| 85 | model_params = [] |
| 86 | for net_name, net_conf in net_confs.items(): |
| 87 | if "quantize_stat" in conf: |
| 88 | net_conf["quantize_stat"] = conf["quantize_stat"] |
| 89 | net_def_with_Data = convert_net(net_name, net_conf, enable_micro) |
| 90 | try: |
| 91 | visualizer = visualize_model.ModelVisualizer( |
| 92 | net_name, net_def_with_Data, model_output) |
| 93 | visualizer.save_html() |
| 94 | except: # noqa |
| 95 | print("Failed to visualize graph:", sys.exc_info()) |
| 96 | net_def, params = merge_params(net_def_with_Data, |
| 97 | net_conf[ModelKeys.data_type]) |
| 98 | if enable_micro: |
| 99 | convert_micro(model_name, net_confs, net_def, |
| 100 | params, model_output,) |
| 101 | |
| 102 | net_def.data_offset = len(model_params) |
| 103 | net_def.data_size = len(params) |
| 104 | model.net_def.extend([net_def]) |
| 105 | model_params.extend(params) |
| 106 | # store model and weight to files |
| 107 | output_model_file = model_output + "/" + model_name + ".pb" |
| 108 | output_params_file = model_output + "/" + model_name + ".data" |
| 109 | with open(output_model_file, "wb") as f: |
| 110 | f.write(model.SerializeToString()) |
| 111 | with open(output_params_file, "wb") as f: |
| 112 | f.write(bytearray(model_params)) |
| 113 | with open(output_model_file + "_txt", "w") as f: |
| 114 | f.write(str(model)) |
| 115 | |
| 116 | |
| 117 | def convert_net(net_name, conf, enable_micro): |
no test coverage detected