Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix dynamic shape inference in DepthToSpace #880

Merged
merged 4 commits into from
Mar 17, 2021

Conversation

d-miketa
Copy link
Contributor

@d-miketa d-miketa commented Mar 15, 2021

Nets using DepthToSpace are currently incompatible with dynamic axes. It's enough to switch from x.shape to tf.shape(x) along with manual unrolling of the resulting 4-dimensional tensor (as one is not allowed to directly iterate over a tf.Tensor).

Related to #543 and #771

Edit: Added a unittest. It's my first one and my second PR ever, so fingers crossed..!

@CLAassistant
Copy link

CLAassistant commented Mar 15, 2021

CLA assistant check
All committers have signed the CLA.

Signed-off-by: Dom Miketa <[email protected]>
@@ -40,7 +40,8 @@ def _common(cls, node, **kwargs):
if mode == "CRD":
# need native computation
bsize = attrs.get("blocksize")
batch, channel, height, width = x.shape
x_shape = tf.shape(x)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First, thanks very much for making the contribution! If you don't mind, please consider use the utility method tf_shape, which takes care of both fully defined and dynamic shapes, and provides slight optimization for static shape.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion, switched to tf_shape.

Comment on lines 251 to 252
def test_depth_to_space(self):
b,c,h,w = shape = [2, 48, 5, 6]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code looks fine. Please run yapf as described in https://github.com/onnx/onnx-tensorflow#code-standard to keep the code format and style consistent. Thanks.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for pointing out that document, done on both files.

@d-miketa d-miketa force-pushed the master branch 2 times, most recently from c9ac540 to fff017b Compare March 16, 2021 10:07
Signed-off-by: Dom Miketa <[email protected]>
Copy link
Collaborator

@chinhuang007 chinhuang007 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@chinhuang007 chinhuang007 merged commit 6685f45 into onnx:master Mar 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants