import onnx
import sys
if __name__ == "__main__":
if len(sys.argv) < 2:
print("usage:program onnx-model")
exit()
model_name = sys.argv[1]
onnx_model = onnx.load(model_name)
graph = onnx_model.graph
nodes = graph.node
inputs = graph.input
outputs = graph.output
initializers = graph.initializer
inputs[0].name = inputs[0].name.replace(".","_")
for i in range(len(nodes)):
for j in range(len(nodes[i].input)):
if "." in nodes[i].input[j]:
nodes[i].input[j] = nodes[i].input[j].replace(".","_")
for j in range(len(nodes[i].output)):
if "." in nodes[i].output[j]:
nodes[i].output[j] = nodes[i].output[j].replace(".","_")
for i in range(len(initializers)):
if "." in initializers[i].name:
initializers[i].name = initializers[i].name.replace(".","_")
onnx.checker.check_model(onnx_model)
onnx.save(onnx_model,"out.onnx")
ONNX 模型节点名称的修改
最新推荐文章于 2024-06-11 15:39:30 发布