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

WinRT information: Failed to load model with error: Unknown model file format version - How do I change the model format version? #3836

Closed
Westy-Dev opened this issue Nov 10, 2021 · 8 comments
Labels
question Questions about ONNX

Comments

@Westy-Dev
Copy link

Ask a Question

Question

I have converted a YoloV5 model to ONNX with the Opset 9. This model works great running a C# program using Microsoft.ML. However, I am now trying to get this model to work with UWP which requires Windows.AI.MachineLearning and I am running into this error:

WinRT information: Failed to load model with error: Unknown model file format version.

I see that my file format version is 7 when I check the model in Netron, whereas example models are format version 4 or 5. How can I change this file format version? I am using an export.py script from Ultralytics - ultralytics/yolov5#251 which perform the conversion from YoloV5 to ONNX. As mentioned above, my model has worked for the Microsoft.ML package, but is not working for Windows.AI.MachineLearning.

I can't find any documentation about the file format version, so I am wondering how I can produce a ONNX model with a different format version as this seems to be the issue.

Many thanks.

@Westy-Dev Westy-Dev added the question Questions about ONNX label Nov 10, 2021
@Westy-Dev
Copy link
Author

image
Here is he model format version as seen by Netron

@jcwchen
Copy link
Member

jcwchen commented Nov 10, 2021

Hi @Westycoot,
In fact, a opset 9 model should have ir_version 4. You can check the corresponding version map here: https://github.com/onnx/onnx/blob/master/docs/Versioning.md. A quick hacky way would be simply trying: your_model.ir_version=4, but it might not work if the model indeed uses some new IR things after ir_version 5... So I would say it's better to check with the converter team and let them take care of old IR format and produce the right ir_version with corresponding opset_version during the conversion. Thanks!

@Westy-Dev
Copy link
Author

Hi @jcwchen ,
Here is some more output of what my model looks like from the conversion process:
image

I will take a look at trying the hack, if that doesnt work I will post a similar thread in the Ultralytics Github. Thanks!

@garymm
Copy link
Contributor

garymm commented Nov 11, 2021

This should be fixed in torch.onnx.export in PyTorch 1.11 by pytorch/pytorch#67128.

@jcwchen I think you can close this.

@jcwchen
Copy link
Member

jcwchen commented Nov 11, 2021

This should be fixed in torch.onnx.export in PyTorch 1.11 by pytorch/pytorch#67128.

@jcwchen I think you can close this.

Great! Thanks for the info. Close here now. @Westycoot feel free to reopen it if you still have other ONNX questions.

@jcwchen jcwchen closed this as completed Nov 11, 2021
@Westy-Dev
Copy link
Author

Westy-Dev commented Nov 11, 2021

It looks like PyTorch 1.11 doesn't have a release yet, how can I get hold of this new export? Many thanks. Hopefully this will solve my issue :)

@Westy-Dev
Copy link
Author

I have managed to get PyTorch 1.11 running, but when I try and export I get this error (I understand this is pre-release):

image

@garymm
Copy link
Contributor

garymm commented Nov 11, 2021

@Westycoot before the 1.11 release you can use the latest PyTorch nightly version.

I guess the model code may not be compatible with the latest version of PyTorch. This PR seems related: pytorch/pytorch#66419

You may have to change the model to be compatible with the latest PyTorch.

But if you've already successfully exported using PyTorch 1.10, I think just editing the ir_version in the exported ONNX file is probably the easiest thing to do.

Something like:

import onnx

model = onnx.load("path/to/model.onnx")
model.ir_version = 4
onnx.save_model(model, "path/to/model.irv4.onnx")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Questions about ONNX
Projects
None yet
Development

No branches or pull requests

3 participants