question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[help]How to export swin model to ONNX? Problem: Node (Concat_246) Op (Concat) [ShapeInferenceError]

See original GitHub issue

I exported my trained model into ONNX by the following code:

    torch.onnx.export(model, input_tensor, onnx_name, verbose=True, opset_version=12, input_names=['images'],
                      output_names=['output'], use_external_data_format=False)

But when running onnx model, I got the following error: onnxruntime.capi.onnxruntime_pybind11_state.Fail: [ONNXRuntimeError] : 1 : FAIL : Node (Concat_246) Op (Concat) [ShapeInferenceError] All inputs to Concat must have same rank

It caused by attn.view(B_ // nW, nW, self.num_heads, N, N) in https://github.com/microsoft/Swin-Transformer/blob/793f971e735b1e27d5e2c683b7a2b53090d3806d/models/swin_transformer.py#L133

The Concat op maybe one parts of torch.view(). Does anyone know how to solve this problem?

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:11
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
xizicommented, Nov 2, 2021

change “attn = attn.view(B_ // nW, nW, self.num_heads, N, N) + mask.unsqueeze(1).unsqueeze(0)” to “attn = attn.view(-1, self.num_heads, N, N) + mask.unsqueeze(1)” can solve the problem.

0reactions
yyjabidingcommented, Apr 21, 2022

The link https://gist.github.com/devymex/51687edd41eef4ccc56d76a0c66bf92c is not avalilable,can you share the code how to export video swin transformer to onnx? thanks.@devymex

Read more comments on GitHub >

github_iconTop Results From Across the Web

No results found

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found