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?

N8allan
  • 2,138
  • 19
  • 32
  • 3
    Add `8.0` to your projct file (as documented [here](https://learn.microsoft.com/en-us/previous-versions/visualstudio/visual-studio-2012/hh708954(v=vs.110)), 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](https://stackoverflow.com/questions/28256102/bluetooth-4-0-low-energy-api-for-windows-desktop-c-sharp-application/28265616#28265616) – Raymond Chen Mar 27 '19 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 01 '19 at 19:02

1 Answers1

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.

Ori Levari
  • 86
  • 1