Skip to content

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

@Oldpan

Description

@Oldpan

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions