当前位置:网站首页>被 onnx.checker.check_model 检查出的常见错误
被 onnx.checker.check_model 检查出的常见错误
2022-04-23 06:12:00 【wujpbb7】
错误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=model.ir_version,
producer_name=model.producer_name,
producer_version=model.producer_version,
opset_import=model.opset_import)
new_model.graph.name = model.graph.name
# 只考虑模型是单输入单输出的情况。
# 这里不需要 copy.deepcopy(model.graph.input[0]), python 是写时copy。
new_model.graph.input.append(model.graph.input[0])
new_model.graph.output.append(model.graph.output[0])
list_total_input_name = [model.graph.input[0].name]
for weight in model.graph.initializer:
new_model.graph.initializer.append(weight)
list_total_input_name.append(weight.name)
list_nodes_invalid = []
for node in model.graph.node:
node_invalid = False
for node_input_name in node.input:
if (list_total_input_name.count(node_input_name) == 0):
list_nodes_invalid.append(node)
node_invalid = True
break
if (node_invalid):
continue
for node_output_name in node.output:
list_total_input_name.append(node_output_name)
new_model.graph.node.append(node)
for node in list_nodes_invalid:
for node_input_name in node.input:
assert list_total_input_name.count(node_input_name) > 0
for node_output_name in node.output:
list_total_input_name.append(node_output_name)
new_model.graph.node.append(node)
return new_model
版权声明
本文为[wujpbb7]所创,转载请带上原文链接,感谢
https://blog.csdn.net/blueblood7/article/details/121253178
边栏推荐
- 面试总结之特征工程
- 【动态规划】不同的二叉搜索树
- Handlerthread principle and practical application
- MySQL数据库安装与配置详解
- 【期刊会议系列】IEEE系列模板下载指南
- Pytorch模型保存与加载(示例)
- [Point Cloud Series] SG - Gan: Adversarial Self - attachment GCN for Point Cloud Topological parts Generation
- Machine learning II: logistic regression classification based on Iris data set
- Raspberry Pie: two color LED lamp experiment
- [2021 book recommendation] learn winui 3.0
猜你喜欢

【点云系列】Pointfilter: Point Cloud Filtering via Encoder-Decoder Modeling

c语言编写一个猜数字游戏编写

红外传感器控制开关

【点云系列】FoldingNet:Point Cloud Auto encoder via Deep Grid Deformation

【点云系列】 A Rotation-Invariant Framework for Deep Point Cloud Analysis
![[2021 book recommendation] practical node red programming](/img/f4/e397c01f1551cd6c59ea4f54c197e6.png)
[2021 book recommendation] practical node red programming

第1章 NumPy基础

WebView displays a blank due to a certificate problem

Easyui combobox 判断输入项是否存在于下拉列表中

Chapter 4 pytoch data processing toolbox
随机推荐
Component based learning (1) idea and Implementation
Component based learning (3) path and group annotations in arouter
SSL/TLS应用示例
Component learning (2) arouter principle learning
Pytorch模型保存与加载(示例)
Pytorch trains the basic process of a network in five steps
WinForm scroll bar beautification
WebView displays a blank due to a certificate problem
Pytorch best practices and coding style guide
DCMTK (dcm4che) works together with dicoogle
Google AdMob advertising learning
深度学习模型压缩与加速技术(一):参数剪枝
MySQL installation and configuration - detailed tutorial
红外传感器控制开关
Pytoch model saving and loading (example)
MySQL notes 5_ Operation data
机器学习 二:基于鸢尾花(iris)数据集的逻辑回归分类
【点云系列】点云隐式表达相关论文概要
1.1 PyTorch和神经网络
Chapter 4 pytoch data processing toolbox