chainer / onnx-chainer

Add-on package for ONNX format support in Chainer
MIT License
85 stars 24 forks source link

[WIP] Add option to handle dynamic shape on reshape node #191

Closed disktnk closed 4 years ago

disktnk commented 5 years ago

Shape size can be changed but ONNX-Chainer cannot deal with it because shape is not represented as computational graph and fixed when passed to functions, like following case:

batch_size = x.shape[0]
x = x.reshape((batch_size, -1))  # batch_size is set to Reshape node as number

To handle this, introduce enable_shape_var option, then chainer.Variable.shape returns as chainer.Variable and make computation graph even shape.

This logic has strong side effect and cannot pass ordinal code such as:

# enable_shape_var = True
shape = x.shape  # returns as chainer.Variable
y = np.empty(shape)  # error because numpy.empty cannot handle Variable type

So pay attention to use this option.

Not set the option:

Screen Shot 2019-07-17 at 17 30 25

Set the option

Screen Shot 2019-07-17 at 17 32 33

TODO:

I'll separate this PR

codecov-io commented 5 years ago

Codecov Report

Merging #191 into master will increase coverage by 0.12%. The diff coverage is 88.11%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #191      +/-   ##
==========================================
+ Coverage   89.57%   89.69%   +0.12%     
==========================================
  Files          24       25       +1     
  Lines        1372     1466      +94     
==========================================
+ Hits         1229     1315      +86     
- Misses        143      151       +8
Impacted Files Coverage Δ
onnx_chainer/mapping.py 90% <ø> (ø) :arrow_up:
onnx_chainer/export.py 91.28% <100%> (+1.11%) :arrow_up:
onnx_chainer/functions/__init__.py 100% <100%> (ø) :arrow_up:
onnx_chainer/replace_func.py 95.18% <100%> (+3.61%) :arrow_up:
onnx_chainer/variable.py 85.33% <85.33%> (ø)
onnx_chainer/functions/array.py 90.16% <87.5%> (-0.18%) :arrow_down:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update ac0963d...cb4fbb0. Read the comment docs.