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

[Bug]: torch.onnx.export fails for higher versions of torch #1158

Closed
ORippler opened this issue Jun 30, 2023 · 4 comments · Fixed by #1159
Closed

[Bug]: torch.onnx.export fails for higher versions of torch #1158

ORippler opened this issue Jun 30, 2023 · 4 comments · Fixed by #1159

Comments

@ORippler
Copy link
Contributor

ORippler commented Jun 30, 2023

Describe the bug

Apparently torch performs runtime type-checking with beartype now (not sure since what version exactly). As a consequence, torch.onnx.export errors during model export since we pass a Path and not str | io.BytesIO types to it.

File <@beartype(torch.onnx.utils.export) at 0x7f496fa14f70>:82, in export(__beartype_func, __beartype_get_violation, __beartype_object_139953382171520, __beartype_object_94218987035792, __beartype_object_139953391361152, __beartype_object_94218985712112, __beartype_object_139957334026176, __beartype_object_94218917833984, __beartype_getrandbits, __beartype_object_94218985711152, __beartype_object_139953396621568, __beartype_object_94218917827408, __beartype_object_139953387959104, __beartype_object_94218918055504, *args, **kwargs)

BeartypeCallHintParamViolation: @beartyped torch.onnx.utils.export() parameter f="PosixPath('/workspaces/ml-docker-dev/anomalib/asdf/results/patchcore/terminal bloc... violates type hint typing.Union[str, _io.BytesIO], as <protocol "pathlib.PosixPath"> "PosixPath('/workspaces/ml-docker-dev/anomalib/asdf/results/patchcore/terminal bloc... not str or <class "_io.BytesIO">.

Can be easily fixed by casting to str in torch.onnx.export

Dataset

N/A

Model

N/A

Steps to reproduce the behavior

  1. install anomalib from master
  2. try to export to onnx

OS information

OS information:

  • OS: [e.g. Ubuntu 20.04]
  • Python version: [e.g. 3.8.10]
  • Anomalib version: [e.g. 0.3.6]
  • PyTorch version: [e.g. 1.9.0]
  • CUDA/cuDNN version: [e.g. 11.1]
  • GPU models and configuration: [e.g. 2x GeForce RTX 3090]
  • Any other relevant information: [e.g. I'm using a custom dataset]

Expected behavior

Export works

Screenshots

No response

Pip/GitHub

pip

What version/branch did you use?

No response

Configuration YAML

n/a

Logs

File <@beartype(torch.onnx.utils.export) at 0x7f496fa14f70>:82, in export(__beartype_func, __beartype_get_violation, __beartype_object_139953382171520, __beartype_object_94218987035792, __beartype_object_139953391361152, __beartype_object_94218985712112, __beartype_object_139957334026176, __beartype_object_94218917833984, __beartype_getrandbits, __beartype_object_94218985711152, __beartype_object_139953396621568, __beartype_object_94218917827408, __beartype_object_139953387959104, __beartype_object_94218918055504, *args, **kwargs)

BeartypeCallHintParamViolation: @beartyped torch.onnx.utils.export() parameter f="PosixPath('/workspaces/ml-docker-dev/anomalib/asdf/results/patchcore/terminal bloc... violates type hint typing.Union[str, _io.BytesIO], as <protocol "pathlib.PosixPath"> "PosixPath('/workspaces/ml-docker-dev/anomalib/asdf/results/patchcore/terminal bloc... not str or <class "_io.BytesIO">.


### Code of Conduct

- [X] I agree to follow this project's Code of Conduct
@ORippler ORippler changed the title [Bug]: torch.onnx.export fails for higher versions [Bug]: torch.onnx.export fails for higher versions of torch Jun 30, 2023
@ORippler
Copy link
Contributor Author

No clue why mypy doesn't detect this though, and the type-error is caught only at run-time. Might be worth digging deeper into this.

@samet-akcay
Copy link
Contributor

that's odd, mypy should have caught in the first place. Thanks for spotting this

@Kyle-fang
Copy link

Hello! I'm using onnx obtained from anomalib and then reasoning with onnxruntime, the input image shape is [1, 3, 256, 256] but the output is [1, 1, 256, 256], isn't it supposed to be the number of categories? Is there a problem with the .onnx file? @samet-akcay @ORippler @Lothiraldan

@ORippler
Copy link
Contributor Author

ORippler commented Aug 8, 2023

Hello! I'm using onnx obtained from anomalib and then reasoning with onnxruntime, the input image shape is [1, 3, 256, 256] but the output is [1, 1, 256, 256], isn't it supposed to be the number of categories? Is there a problem with the .onnx file? @samet-akcay @ORippler @Lothiraldan

The output is a heatmap, so everything is working as expected

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

Successfully merging a pull request may close this issue.

3 participants