错误1:“Field 'name' of graph is required to be non-empty.”
解决:对 model.graph.name 赋值。
错误2:“Nodes in a graph must be topologically sorted, however input ...”
解决:调整节点顺序,保证每个节点的输入都先于它存在。
参考代码如下:
def check_update_model(model):
if (model.graph.name == ''):
model.graph.name = 'tackle_checker_error'
try:
onnx.checker.check_model(model)
except onnx.checker.ValidationError as e:
print("model is invalid: %s"%(e))
# 目前只考虑这个错误“ Nodes in a graph must be topologically sorted, however input ...”,
# 就是模型的节点顺序有问题,onnxruntime 是可以推断的,为了其他引擎比如 trt可以推断,调整一下节点顺序。
else:
return model
print('update model ...')
new_model = onnx.ModelProto(ir_version=mode