2

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?

2
  • 3
    Add <TargetPlatformVersion>8.0</TargetPlatformVersion> to your projct file (as documented here, and then you can use "Add Reference > Windows > Core" to add a reference to Windows.AI. Also add a reference to System.Runtime. Another answer Mar 27, 2019 at 18:26
  • Thank you for sending me in the right direction @Raymond. The TargetPlatformVersion should be set to 10. For some reason I still couldn't reference AsRandomAccessStream from System.Windows, but I decided to switch to Onnx Runtime instead, for portability. You should make this an actual answer by the way.
    – N8allan
    Apr 1, 2019 at 19:02

1 Answer 1

7

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.

2
  • Awesome. Thanks for that!
    – N8allan
    Apr 1, 2019 at 22:07
  • Awesome! Did help a lot.
    – Avrohom
    Jun 26, 2019 at 0:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.