microsoft/Windows-Machine-Learning

Failed to load model with error: Unknown model file format version

Regenhardt opened this issue · 3 comments

I'm submitting a Bug report like #386

It seems 386 was closed due to inactivity, not because it is solved. Internet search sent me there so that's bad.

The sample code is directly from the (non-compilable☹) MS Docs sample

//  o11 here means exported for opset 11
var modelFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/mob_50k_B16_o11.onnx"));
model = await LearningModel.LoadFromStorageFileAsync(modelFile);
var device = new LearningModelDevice(LearningModelDeviceKind.Cpu);
session = new LearningModelSession(model, device); // Exception here, message is in the title

Current behavior

Model created with opset 11 can't be used to create session even though the NuGet Package is installed.

Expected behavior

The documentation says opset 11 is supported, so a LearningSession should be created.

Minimal reproduction of the problem with instructions

  • Train tensorflow model (in this case on top of mobilenet)
  • export to saved model
  • Convert to onnx format using tf2onnx according to MS Docs
  • New UWP app targeting 2004, install Microsoft.AI.MachineLearning
  • Try to load model according to above code sample

...or use the code from the MS Docs guide I followed.

Environment

Windows Build Number: 21H2 build 19044.1706

App min and target version: 2004

OS Version (Server, IoT Core, Desktop, etc): Win 10 Pro

Graphics Driver version: 27.21.14.5266

DxDiag:

WinMLTools specific:
- Source training framework: TensorFlow
- WinMLTools version

Visual Studio

  • 2022 (version: 17.2.2)

Btw your template is out of date it still has VS 2017 in it.

Hi,

Thanks for posting. 386 was closed because the user was trying to load a model with an unsupported file format version.

What version of the NuGet package are you using? Per our current tests, a model created with opset 11 should work to create a session with the most recent version of the NuGet package which can be found here

Closing as stale. Please feel free to reopen.

Hi @Regenhardt,
I don't know if it matters now, but I faced a similar issue as yours i.e. had an opset 11 model that threw the "Failed to load model with error: unknown model file format version" error. It turns out that the OS version also plays a role. In particular, Windows 10 supports models only up to opset 9 apparently - see here for reference. Once I re-exported my model at opset 9 it worked like a charm.

Hope this helps.