Comments (13)
@varunarora Yes, property shape
can be set to None
in the latest master branch, while in the release 1.0.1 it cannot be, see here.
In principle, the shape of all the mediate tensors can be infered from inputs and parameters automatically in runtime. But unfortunately some backends may do dimension checking for each operator when importing models. For instance, I tried to assign some random values to the shape
property here
and failed to run the converted fit_a_line
model by using onnx-tensorrt backend, and got the error like:
/xxx/onnx-tensorrt/builtin_op_importers.cpp:693 In function importMatMul:
[6] Assertion failed: weights.shape.d[1] == ninput
Seems that we have no choice but to set the right shape here in models' converting. But the first dimension is an exception, which is interpreted as the batch size, and it can be initialized by zero or any positive intergers and infered correctly in runtime.
@postrational @baojun-nervana We chose dim_value 0
instead of dim_param
to indicate the unknown batch size because it is more close to our convention(-1 in Fluid but caffe2 backend doesn't support). And we checked the models in onnx/models, they also use 0
for the batch size (not sure it is true for all models or any update after that). So can this dimension be inferred automatically in ngraph-onnx even we can set it to 1
?
from paddle2onnx.
#54 is a simple workaround for the 0
dimension in shape, which forces any 0
to a 1
.
You may want to parametrise the 1
value instead of hard-coding it or find another fix.
from paddle2onnx.
I wonder how to define unknown dimension in ngraph-onnx. The converted models have been tested on TensorRT and caffe2 ONNX backend. It is the problem of ngraph-onnx if it cannot important models following the ONNX specifications. You'd better consider to fix ngraph-onnx to support dim 0.
from paddle2onnx.
@kuke Could you point us to the part of the ONNX specification, which talks about how dim 0 should be supported?
from paddle2onnx.
@kuke It sounds some FWs can handle undefined dimensions (TensorRT), while others may not (like nGraph). Very likely another FW besides nGraph can encounter the similar issue. In the case we are discussing, it refers to batch size and we can enforce it to some other value. If the dim0 refer to anything else, it can be hard to work around. Paddle-ONNX will be one that knows what those dim_value represent and the best place to handle it. Is there any problem to have a default/defined value other than 0?
from paddle2onnx.
@postrational https://github.com/onnx/onnx/blob/master/docs/IR.md#tensor-shapes
from paddle2onnx.
@kuke On the basis of the specification, I guess the shape
property should be undefined from the tensor record? I know the make_tensor
requires a value to be passed for dimension, but make_tensor_value_info
allows us to pass a None
- I think.
from paddle2onnx.
@varunarora
If I'm reading these docs correctly, they do not allow for a 0
dim value.
Each size in the list MUST be expressed as:
- an integral value
- or as a "dimension variable," a string denoting that the actual size of the dimension is not statically constrained to a particular number. This is useful for declaring interfaces that care about the number of dimensions, but not the exact size of each dimension.
The emptry string "", when used as a dimension name, denotes a single dimension of any cardinality.
As far as I can tell, if you want to express an unknown dim value in ONNX, you should not use dim_value=0
, but instead use dim_param=''
.
This will not help us however, as nGraph will still need to set this to some value to build a static graph.
from paddle2onnx.
I fully understand @postrational. Have you read the part that says:
A zero-dimension tensor is distinct from a tensor of unknown dimensionality, which is indicated by an absent 'shape' property in the Tensor record. When the shape property is absent for an input, a tensor value of any shape may be passed from the caller
As @kuke pointed out, it would only be right to make these changes at the nGraph-ONNX project level, because unknown dimensionality is allowed from a spec perspective, whichever way it is set. Makes lesser sense to change it in this convertor.
from paddle2onnx.
@varunarora If I understand the docs correctly, a "zero-dimension tensor" is a tensor with no dimensions denoting a scalar value (not one with a dimension set to 0
).
The empty list of dimension sizes, [], is a valid tensor shape, denoting a zero-dimension (scalar) value. A zero-dimension tensor is distinct from a tensor of unknown dimensionality...
@kuke Could you tell us which model in https://github.com/onnx/models uses a 0
shape?
from paddle2onnx.
Yep @postrational agreed, we need to eliminate the shape
property from tensors of unknown dimensionality. We don't have it right. The purpose to show you that tensors of dimensionality 0 are allowed, even if we don't use them fully correctly.
from paddle2onnx.
@postrational It was several months ago that I checked one or two binary models, now they have detailed READMEs and seems that those models take one image as input. But this is not the point. The important thing is whether an ONNX backend can infer this dimension correctly from inputs. Now that dim 0/1
or some other value is just a placeholder, we can use dim_value==1
for the unknown batch size. Hope that it will help to solve your problem. And @varunarora , what is your opinion?
from paddle2onnx.
I have made some preliminary support for undefined shapes at #104
from paddle2onnx.
Related Issues (20)
- there are some operators not supported yet, including distribute_fpn_proposals,generate_proposals_v2
- [Discussion] Standardized Process for Publishing a Release Branch HOT 18
- ch_ppstructure_mobile_v2.0_SLANet表格识别模型转rknn模型报错 HOT 1
- An error while attempting to convert a PaddlePaddle model to ONNX format HOT 3
- re_vi_layoutxlm_xfund_infer转换ONNX失败 HOT 1
- Cannot found attribute threshold in op: relu6 HOT 4
- 量化模型导出onnx,模型失效 HOT 1
- 如何将paddle模型中的sub_block导出成onnx
- PaddleSeg-release-2.8.1 的量化模型转onnx onnx转rknn 没有成功的问题 HOT 2
- [Discussion] 迁移Paddle2ONNX构建方式到Python 新规范(pyproject.toml) HOT 7
- ] Oops, there are some operators not supported yet, including prior_box, HOT 1
- 紧急,PaddleSeg中的OCRNet模型导出为onnx,推理失败 HOT 7
- paddle模型本来是不固定输入输出的,但是使用Paddle2ONNX转换必须指定input_size,不然会报Due to the operator: pool2d, this model cannot be exported to ONNX错 HOT 2
- paddle2onnx 在尝试将 PaddlePaddle 模型转换为 ONNX 格式时遇到了不支持的算子(operators):distribute_fpn_proposals 和 generate_proposals_v2。由于这些算子在 ONNX 规范中没有直接的等价实现或者paddle2onnx转换工具中尚未实现对这些算子的支持,转换过程被中止了 HOT 1
- Matting模型转换为ONNX时报错 [pool2d: pool2d_10.tmp_0] While Attribute(ksize)'s type is Tensor, it's not supported. HOT 2
- 【开源之夏】飞桨PaddlePaddle-PIR适配Paddle2ONNX推理转换
- [Discussion] 请求提供 Paddle2ONNX 开发者培训计划 HOT 8
- 转换paddlespeech的KWS部署模型出现了问题
- 无法通过pip install paddle2onnx安装,同时也无法通过编译安装 HOT 6
- paddleseg模型和onnx模型的推理结果不一致,精度差距较大 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from paddle2onnx.