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

How to convert pytorch to onnx? #73

Open
jeromezyb opened this issue Mar 13, 2022 · 3 comments
Open

How to convert pytorch to onnx? #73

jeromezyb opened this issue Mar 13, 2022 · 3 comments

Comments

@jeromezyb
Copy link

tools/pytorch2onnx.py

python tools/pytorch2onnx.py configs/swin/upernet_swin_tiny_patch4_window7_512x512_160k_ade20k.py

Error: Exporting the operator roll to ONNX opset version 11 is not supported. Please open a bug to request ONNX export support for the missing operator.

@romil611
Copy link

I'm also looking to convert the model to onnx. If possible please suggest alternate for roll operator. thanks.

@wanchunwu-gorilla
Copy link

Add the following code to pytorch/torch/onnx/symbolic_opset11.py:

@parse_args('v', 'is', 'is')
def roll(g, self, shifts, dims):
    assert len(shifts) == len(dims)

    result = self
    for i in range(len(shifts)):
        shapes = []
        shape = sym_help._slice_helper(g,
                                       result,
                                       axes=[dims[i]],
                                       starts=[-shifts[i]],
                                       ends=[maxsize])
        shapes.append(shape)
        shape = sym_help._slice_helper(g,
                                       result,
                                       axes=[dims[i]],
                                       starts=[0],
                                       ends=[-shifts[i]])
        shapes.append(shape)
        result = g.op("Concat", *shapes, axis_i=dims[i])

    return result

Reference: pytorch/pytorch#68974

@Kaunain26
Copy link

Add the following code to pytorch/torch/onnx/symbolic_opset11.py:

@parse_args('v', 'is', 'is')
def roll(g, self, shifts, dims):
    assert len(shifts) == len(dims)

    result = self
    for i in range(len(shifts)):
        shapes = []
        shape = sym_help._slice_helper(g,
                                       result,
                                       axes=[dims[i]],
                                       starts=[-shifts[i]],
                                       ends=[maxsize])
        shapes.append(shape)
        shape = sym_help._slice_helper(g,
                                       result,
                                       axes=[dims[i]],
                                       starts=[0],
                                       ends=[-shifts[i]])
        shapes.append(shape)
        result = g.op("Concat", *shapes, axis_i=dims[i])

    return result

Reference: pytorch/pytorch#68974

this did not work. :(

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

4 participants