MCPcopy Create free account
hub / github.com/OpenPPL/ppq / export_weights

Method export_weights

ppq/parser/tensorRT.py:93–113  ·  view source on GitHub ↗
(self, graph: BaseGraph, config_path: str = None)

Source from the content-addressed store, hash-verified

91 json_file.write(json_qparams_str)
92
93 def export_weights(self, graph: BaseGraph, config_path: str = None):
94 topo_order = graph.topological_sort()
95 weights_list = []
96 for index, op in enumerate(topo_order):
97 if op.type in {"Conv", "Gemm"}:
98 weights_list.extend(op.parameters)
99
100 weight_file_path = os.path.join(os.path.dirname(config_path), "quantized.wts")
101
102 f = open(weight_file_path, 'w')
103 f.write("{}\n".format(len(weights_list)))
104
105 for param in weights_list:
106 weight_name = param.name
107 weight_value = param.value.reshape(-1).cpu().numpy()
108 f.write("{} {}".format(weight_name, len(weight_value)))
109 for value in weight_value:
110 f.write(" ")
111 f.write(struct.pack(">f", float(value)).hex())
112 f.write("\n")
113 ppq_info(f'Parameters have been saved to file: {weight_file_path}')
114
115
116 def export(self, file_path: str, graph: BaseGraph, config_path: str = None, input_shapes: List[List[int]] = [[1, 3, 224, 224]]):

Callers 1

exportMethod · 0.95

Calls 2

ppq_infoFunction · 0.90
topological_sortMethod · 0.80

Tested by

no test coverage detected