Skip to content

Instantly share code, notes, and snippets.

@meulta meulta/wrapper.cs
Created May 17, 2018

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("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
You can’t perform that action at this time.