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)
- 【🚀需求🚀】支持控制流conditional_block + select_input 系列算子的支持 HOT 4
- 【🚀需求🚀】支持飞桨 swiglu 算子转ONNX HOT 1
- 【🚀需求🚀】支持飞桨 top_p_sampling 算子转ONNX HOT 1
- paddle2onnx 编译python wheel 包问题 HOT 4
- TypeError: export() got an unexpected keyword argument 'model_file' HOT 1
- paddle ocr 转onnx之后精度损失 HOT 10
- paddleocr:export onnx and inference error
- SLANet-LCNetV2 转onnx模型报错 HOT 8
- 无法在set_value算子中找到fp32_values属性 HOT 7
- windwos下安装,版本是旧版本 HOT 1
- 中文表格识别模型ch_ppstructure_mobile_v2.0_SLANet_infer,不支持转为onnx格式吗? HOT 5
- 如何导出NAFNetLocal模型文件为onnx格式?
- Convert Paddle language models to onnx
- 无法在assign_value算子中找到fp32_values和int64_values属性 HOT 2
- Fairmot跟踪模型可以转换为onnx格式吗
- paddlenlp Taskflow("ner") 2 onnx 报错 HOT 1
- 导出onnx模型报错 HOT 12
- 中文表格识别模型ch_ppstructure_mobile_v2.0_SLANet_infer ONNX半精度推理报错
- 中文表格识别模型ch_ppstructure_mobile_v2.0_SLANet_infer ONNX半精度推理报错
- faster rcnn r50 fpn模型转为onnx格式失败
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.