Search code examples
c#windows-10onnxwindows-machine-learning

Cannot find the ONNX file specified using WinML


I am trying to load an ONNX model using WinML, with the following code:

private async Task InitializeModelAsync()
{
    var path = @"ms-appx:///Assets/FER-Emotion-Recognition.onnx";
    var file = await StorageFile.GetFileFromApplicationUriAsync(new Uri(path));
    model = await CNTKGraphModel.CreateCNTKGraphModel(file);
}

The project compiles OK, but during run-time I am getting a System.IO.FileNotFoundException:

The system cannot find the file specified.

I double checked but the file is indeed in the right folder. What did I do wrong?


Solution

  • Right click on your onnx file, go to the Properties panel and set its Build Action to Content.

    Then, set the Copy to Output Directory to Copy if newer.

    enter image description here

    enter image description here

    enter image description here

    See Get started with Machine Learning