[ShapeInferenceError] Mismatch between number of source and target dimensions. Source=1 Target=0
Pytorch转ONNX模型正常,但使用onnxruntime加载onnx模型,会输出错误:
onnxruntime.capi.onnxruntime_pybind11_state.Fail: [ONNXRuntimeError] : 1 : FAIL : Exception during loading: /onnxruntime_src/onnxruntime/core/graph/function.cc:420 onnxruntime::FunctionImpl::FunctionImpl(const onnxruntime::Graph&, const NodeIndex&, const onnx::FunctionProto&, const onnxruntime::logging::Logger&) status.IsOK() was false. Resolve subgraph failed:Node (0x2b97890_109) Op (Loop) [TypeInferenceError] Graph attribute inferencing failed: Node:0x2b97890_109 Output:cond [ShapeInferenceError] Mismatch between number of source and target dimensions. Source=1 Target=0
相关issues:https://github.com/microsoft/onnxruntime/issues/1164
从报错的描述,大致可以定位是输出的维度有问题:于是我详细Debug一下模型输出的'boxes', 'scores'的维度变化:
scores输出维度是(1,13375,2),对应(batch_size,num_anchors,num_class)
boxes输出维度是(13375,4),没有batch_size这个维度,这是因为我进行boxes.data.squeeze(0)处理,不小心把batch_size去掉了
于是我修改源代码,保持'boxes', 'scores'都含有batch_size这个维度,变成
scores输出维度是(1,13375,2),对应(batch_size,num_anchors,num_class)
boxes输出维度是(1,13375,4),对应(batch_size,num_anchors,(x,y,cx,cy))
done,重新生成ONNX模型,并使用onnxruntime加载模型,就没有错误了
结论:转换ONNX模型时,输入输出尽量保留batch_size这个维度,尽管batch_size这个维度经常为1
相关文章
- Leetcode: Walls and Gates
- 解决MySQL报错:1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated column 'informat
- What's the difference between `.class1.class2` and `.class1 .class2` CSS rule?
- Download and Installation of Kibana
- Owin and Startup class
- how to backup and restore database of SQL Server
- Multiples of 3 and 5
- Making Use of Forms and Fieldsets
- 解决 warning 显示 The linear_assignment function is deprecated in 0.21 and will be removed from 0.23. Use scipy.optimize.linear_sum_assignment instead
- [42000]关键字 ‘UNION‘ 附近有语法错误。 (156) or > 1221 - Incorrect usage of UNION and ORDER BY
- 【CF553E】Kyoya and Train 最短路+cdq分治+FFT
- HDU 1668 Islands and Bridges
- Chapter 18 MySQL NDB Cluster 7.3 and NDB Cluster 7.4渣翻
- CURRENT-OFFSET and LAG of kafka consumer group that has no active members
- Class hierarchy of UIResponder as well as subclasses of UIView and UIControl
- .NET错误The 'targetFramework' attribute in the <compilation> element of the Web.config file is used only to target version 4.0 and later of the .NET Framework
- SAP MM: Change of material moving average price after goods receipt and invoice verification posting for PO
- [LeetCode] Best Time to Buy and Sell Stock III
- Lessons on Prototyping for Early Entrepreneurs and Startups
- 每日一篇文献:Robotic pick-and-place of novel objects in clutter with multi-affordance grasping and cross-domain image matching
- Human Robot Interaction - VR and Digital Twin Based Teleoperation of Robotic Arm
- 论文阅读:Making Virtual Pancakes — Acquiring and Analyzing Data of Everyday Manipulation Tasks through Interactive Physics-based Simulations
- 论文阅读:On-line simultaneous learning and recognition of everyday activities from virtual reality performances
- 论文阅读: A Review of Robot Learning for Manipulation: Challenges, Representations, and Algorithms
- Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggre
- cf443A Anton and Letters
- CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
- [CareerCup] 13.9 Aligned Malloc and Free Function 写一对申请和释放内存函数
- HAProxy Installation and Configuration on CentOS 6.4 to Mitigate The Effects of Abusive Clients--转
- 《YOLOv4:Optimal Speed and Accuracy of Object Detection》论文笔记