lukemelas/EfficientNet-PyTorch

How to tranform efficient-pytorch to efficient-onnx

peyer opened this issue · 14 comments

peyer commented

I have tried to convert efficient-pytorch to efficient-onnx with api (torch.onnx.export), but I meet a problem showing below info
Failed to export an ONNX attribute, since it's not constant, please try to make things (e.g., kernel size) static if possible
How could I fix it ?

Yes, I can try to make the kernel size static in the next significant update.

peyer commented

@lukemelas Thansk!

Done! I had to change some things with the padding, so it took a little while.

Here is an example:
https://colab.research.google.com/drive/1rOAEXeXHaA8uo3aG2YcFDHItlRJMV0VP

Closing this issue, but definitely re-open if you have any issues.

Also, let me know if exporting to ONNX / mobile works for you!

peyer commented

@lukemelas Successd and thanks!

Great to hear!

@lukemelas Hey! Appreciate your great work.
For the latest version, exporting to onnx fails due to Swish. Any ideas?

Please use model.set_swish(memory_efficient=False).

@bkhti4 Thanks! When I replaced SwishImplementation() with Swish(), I converted the model to onnx successfully.

How there's nn.SiLU as well, so I believe all models should be memory-efficient and exportable :)

The older functions are still included for backward compatibility with old versions of PyTorch

@lukemelas Hi, when I simply ran

model = EfficientNet.from_name(model_name='efficientnet-b0')
model.eval()
model.set_swish(memory_efficient=False)
torch.onnx.export(model, torch.rand(10, 3, 240, 240), "EfficientNet-B0.onnx")

, and got error as blow, any ideas? Thanks.
RuntimeError: Exporting the operator silu to ONNX opset version 9 is not supported. Please open a bug to request ONNX export support for the missing operator.

environment:
Ubuntu 20.04
torch 1.7.1
cuda 11.0
efficientnet-pytorch 0.7.1

@lukemelas嗨,当我简单地跑步时

model = EfficientNet.from_name(model_name='efficientnet-b0')
model.eval()
model.set_swish(memory_efficient=False)
torch.onnx.export(model, torch.rand(10, 3, 240, 240), "EfficientNet-B0.onnx")

,并因错误而遭受打击,有什么主意吗?谢谢。
RuntimeError: Exporting the operator silu to ONNX opset version 9 is not supported. Please open a bug to request ONNX export support for the missing operator.

环境:
Ubuntu 20.04
火炬1.7.1
cuda 11.0
高效net-pytorch 0.7.1

Is it resolved? I need your help!

@aojue1109 I converted the model to onnx successfully. There's my gist link.
If still not solve your problem I think you should re-open the issue.

@chilin0525 thanks!!