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

[Relay][Frontend][ONNX] Should flatten op is converted to batch_flatten ? #3167

Closed
Oldpan opened this issue May 10, 2019 · 3 comments
Closed

Comments

@Oldpan
Copy link
Contributor

Oldpan commented May 10, 2019

There is a bug in onnx frontend I think.
When I using onnx model which has a flatten op with axis attribute and the value is 1.
And then I run relay.frontend.from_onnx , it will occur a issue :

batch_flatten() got an unexpected keyword argument 'axis'

So I modify the source code in .../relay/op/nn/nn.py - line 429.
Change

def batch_flatten(data):

to

def batch_flatten(data, axis=1):

And it works but obviously this is a temporary solution.
I see this pull request #2843 had renamed 'Flatten' to 'batch_flatten'.
Although flatten with default axis 1 is just same as batch_flatten but I think this behavior should be regulated. Probably we can use reshape op to replace flatten and don't rename flatten :

def flatten(data, axis=1):

    newshape = [0]*(axis+1)
    newshape[axis] = -1;
    return _make.reshape(data, list(newshape))

It can work but I'm not sure it is suitable.

@tqchen
Copy link
Member

tqchen commented May 10, 2019

Thanks for bringing this up, we can do an optional conversion(convert to batch_flatten when it matches, use reshape otherwise) We can also enhance batch_flatten. Contribution is welcomed!

@Oldpan
Copy link
Contributor Author

Oldpan commented May 11, 2019

Thanks for reply.
I'LL try a contribution for this

@tqchen
Copy link
Member

tqchen commented May 13, 2019

#3180 Thanks @Oldpan

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

No branches or pull requests

2 participants