mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-05-14 20:48:00 +00:00
* bump cswinrt version * add cswinrt * test dotnetcore 3.0 * rename buildpacakge source * set folder path to the package source and not the version * refactor .netframework tests * build .net core anycpu Co-authored-by: Sheil Kumar <sheilk@microsoft.com>
77 lines
3.4 KiB
C#
77 lines
3.4 KiB
C#
using System;
|
|
using System.IO;
|
|
|
|
using Microsoft.AI.MachineLearning;
|
|
using WinRT;
|
|
|
|
namespace Microsoft.AI.MachineLearning.Tests
|
|
{
|
|
class Program
|
|
{
|
|
static void PerformInference(Windows.Media.VideoFrame frame)
|
|
{
|
|
Console.WriteLine("Load squeezenet.onnx.");
|
|
using (var model = Microsoft.AI.MachineLearning.LearningModel.LoadFromFilePath("squeezenet.onnx"))
|
|
{
|
|
Console.WriteLine("Create LearningModelSession.");
|
|
using (var session = new Microsoft.AI.MachineLearning.LearningModelSession(model))
|
|
{
|
|
Console.WriteLine("Create LearningModelBinding.");
|
|
var binding = new Microsoft.AI.MachineLearning.LearningModelBinding(session);
|
|
Console.WriteLine("Bind data_0.");
|
|
binding.Bind("data_0", frame);
|
|
Console.WriteLine("Evaluate.");
|
|
var results = session.Evaluate(binding, "");
|
|
}
|
|
Console.WriteLine("Success!\n");
|
|
}
|
|
}
|
|
static void Main(string[] args)
|
|
{
|
|
Console.WriteLine("Load kitten_224.png as StorageFile.");
|
|
var name = AppDomain.CurrentDomain.BaseDirectory + "kitten_224.png";
|
|
var getFileFromPathTask = Windows.Storage.StorageFile.GetFileFromPathAsync(name);
|
|
getFileFromPathTask.AsTask()
|
|
.ContinueWith<Windows.Storage.Streams.IRandomAccessStreamWithContentType>(
|
|
(task) =>
|
|
{
|
|
var image = task.Result;
|
|
Console.WriteLine("Load StorageFile into Stream.");
|
|
var stream_task = image.OpenReadAsync();
|
|
// https://github.com/microsoft/CsWinRT/issues/335
|
|
return stream_task.AsTask().Result;
|
|
})
|
|
.ContinueWith<Windows.Graphics.Imaging.BitmapDecoder>(
|
|
(task) =>
|
|
{
|
|
using (var stream = task.Result)
|
|
{
|
|
Console.WriteLine("Create SoftwareBitmap from decoded Stream.");
|
|
var decoder_task = Windows.Graphics.Imaging.BitmapDecoder.CreateAsync(stream);
|
|
// https://github.com/microsoft/CsWinRT/issues/335
|
|
return decoder_task.AsTask().Result;
|
|
}
|
|
})
|
|
.ContinueWith<Windows.Graphics.Imaging.SoftwareBitmap>(
|
|
(task) =>
|
|
{
|
|
var decoder = task.Result;
|
|
var software_bitmap_task = decoder.GetSoftwareBitmapAsync();
|
|
// https://github.com/microsoft/CsWinRT/issues/335
|
|
return software_bitmap_task.AsTask().Result;
|
|
})
|
|
.ContinueWith(
|
|
(task) =>
|
|
{
|
|
using (var software_bitmap = task.Result)
|
|
{
|
|
Console.WriteLine("Create VideoFrame.");
|
|
var frame = Windows.Media.VideoFrame.CreateWithSoftwareBitmap(software_bitmap);
|
|
PerformInference(frame);
|
|
}
|
|
})
|
|
.Wait();
|
|
|
|
}
|
|
}
|
|
}
|