Instantly share code, notes, and snippets.

Embed
What would you like to do?
Generated wrapper for an ONNX file to use in Windows ML
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