Created
May 17, 2018 23:38
-
-
Save meulta/f4d6c9b8aa69ad76d0ef18dbbfce4fd7 to your computer and use it in GitHub Desktop.
Generated wrapper for an ONNX file to use in Windows ML
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Threading.Tasks; | |
using Windows.Media; | |
using Windows.Storage; | |
using Windows.AI.MachineLearning.Preview; | |
namespace MyNamespace | |
{ | |
public sealed class MyModelInput | |
{ | |
public VideoFrame data { get; set; } | |
} | |
public sealed class MyModelOutput | |
{ | |
public IList<string> classLabel { get; set; } | |
public IDictionary<string, float> loss { get; set; } | |
public MyModelOutput() | |
{ | |
this.classLabel = new List<string>(); | |
this.loss = new Dictionary<string, float>(); | |
} | |
} | |
public sealed class MyModel | |
{ | |
private LearningModelPreview learningModel; | |
public static async Task<MyModel> CreateMyModel(StorageFile file) | |
{ | |
LearningModelPreview learningModel = await LearningModelPreview.LoadModelFromStorageFileAsync(file); | |
MyModel model = new MyModel(); | |
model.learningModel = learningModel; | |
return model; | |
} | |
public async Task<MyModelOutput> EvaluateAsync(MyModelInput input) { | |
MyModelOutput output = new MyModelOutput(); | |
LearningModelBindingPreview binding = new LearningModelBindingPreview(learningModel); | |
binding.Bind("data", input.data); | |
binding.Bind("classLabel", output.classLabel); | |
binding.Bind("loss", output.loss); | |
LearningModelEvaluationResultPreview evalResult = await learningModel.EvaluateAsync(binding, string.Empty); | |
return output; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment