Search code examples
c#windows-machine-learning

Can Windows ML learning models be accessed by C# outside of UWP?


I have an ONNX model I wish to evaluate images against, from a C# Windows service (non UWP). I don't see any way to get to the Windows ML framework from C# outside of building a UWP app, is that correct?

I found this posting which seems to indicate that it is possible from C++.

Is there at least a well known COM wrapper or something for it?


Solution

  • See here for an example on the Windows-Machine-Learning GitHub of a slightly different method of referencing Windows.AI.MachineLearning outside of UWP: https://github.com/Microsoft/Windows-Machine-Learning/tree/master/Samples/SqueezeNetObjectDetection/NETCore/cs

    To recreate this sample create a .NET Core sample and add an assembly reference to the Windows.winmd file of the Windows SDK. The path to this file may look like: C:\Program Files (x86)\Windows Kits\10\UnionMetadata[version]\Windows.winmd.

    This will allow you to access Windows.AI.MachineLearning in a non-UWP c# app. This sample uses an environment variable to parametrize the path to this Windows.winmd, but you can hard code this value if you'd like.