Cannot load model using WinML

2019-08-22 10:28发布

问题:

As WinML is still fairly new and ever changing, I was hoping to know if anyone else has come across this error when trying to load a ONNX file made via the Custom Vision Service Export.

Type Error: Type (map(string,tensor(float))) of output arg (loss) of node (ZipMap) does not match expected type (seq(map(string,tensor(float))))

using Windows.AI.MachineLearning;

Windows RS5 1809 (build 17763.1) UWP SDK 17763

Testing code from this link: https://docs.microsoft.com/en-us/uwp/api/windows.ai.machinelearning

                // Load and create the model
            var modelFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri($"ms-appx:///{_modelFileName}"));
            _model = await LearningModel.LoadFromStorageFileAsync(modelFile);

Any help would be greatly appreciated.

回答1:

Windows build 17763 (RS5) requires ONNX version 1.2 when Windows.AI.MachineLearning.

The Azure Custom Vision service supports this today .

Here is a post around a sample app that does this.

As a note, you need to make sure your output data type matches when you bind. In c# this looks something like this:

 public sealed class ModelOutput
        {
            public TensorString ClassLabel = TensorString.Create(new long[] { 1, 1 });
            public IList<IDictionary<string, float>> Loss = new List<IDictionary<string, float>>();
        }


回答2:

I received info from a Microsoft associate that stated that the windows.ai.machinelearning api only supports ONNX 2. He didn't supply a date to which we can expect the custom vision service to export version 2 files.