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

swin_transformer in pytorch fails to run after converting to onnx #19280

Open
chenglopl opened this issue Jan 26, 2024 · 2 comments
Open

swin_transformer in pytorch fails to run after converting to onnx #19280

chenglopl opened this issue Jan 26, 2024 · 2 comments
Labels
platform:windows issues related to the Windows platform stale issues that have not been addressed in a while; categorized by a bot

Comments

@chenglopl
Copy link

Describe the issue

After converting the swin_transformer model under the pytorch framework into an onnx model and enabling dynamic input, the following error occurs:

onnxruntime.capi.onnxruntime_pybind11_state.RuntimeException: [ONNXRuntimeError] : 6 : RUNTIME_EXCEPTION : Non-zero status code returned while running Reshape node. Name:'Reshape_2' Status Message: /onnxruntime_src/onnxruntime/core/providers/cpu/tensor/reshape_helper.h:42 onnxruntime::ReshapeHelper::ReshapeHelper(const onnxruntime::TensorShape&, std::vector&) gsl::narrow_cast<int64_t>(input_shape.Size()) == size was false. The input tensor cannot be reshaped to the requested shape. Input shape:{4,96,64,64}, requested shape:{1,96,4096}

Locate the error statement as x = x.view (-1, H * W, C),Using visual tools to view this layer is as follows:
image
The reshape parameter of this layer is recorded as a fixed value. How can I modify it to solve this problem

To reproduce

The conversion code is as follows:
torch.onnx.export(model, (input0, input1), "./best.onnx", verbose=True, input_names=['input0', 'input1'], output_names=['output'], dynamic_axes={'input0':{0:'batch', 2:'height',3:'width'}, 'input1':{0:'batch'}, 'output':{0:'batch'}}, opset_version=11)

Urgency

No response

Platform

Windows

OS Version

ubuntu18.04

ONNX Runtime Installation

Released Package

ONNX Runtime Version or Commit ID

1.7.0

ONNX Runtime API

Python

Architecture

X64

Execution Provider

Default CPU

Execution Provider Library Version

No response

@github-actions github-actions bot added the platform:windows issues related to the Windows platform label Jan 26, 2024
@tianleiwu
Copy link
Contributor

tianleiwu commented Jan 26, 2024

Could you try the following:

pip install --upgrade transformers optimum onnxruntime
python -m optimum.exporters.onnx -m microsoft/swin-base-patch4-window12-384-in22k --task image-classification swim_onnx

Tested with transformers==4.37.1 optimum==1.16.2 torch==2.1.1

 -[✓] ONNX model output names match reference model (logits)
        - Validating ONNX Model output "logits":
                -[✓] (2, 21841) matches (2, 21841)
                -[✓] all values close (atol: 1e-05)

Copy link
Contributor

This issue has been automatically marked as stale due to inactivity and will be closed in 30 days if no further activity occurs. If further support is needed, please provide an update and/or more details.

@github-actions github-actions bot added the stale issues that have not been addressed in a while; categorized by a bot label Feb 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform:windows issues related to the Windows platform stale issues that have not been addressed in a while; categorized by a bot
Projects
None yet
Development

No branches or pull requests

2 participants