From 3624f7c5a5d1bba95adca9e580e73daf808b4c45 Mon Sep 17 00:00:00 2001 From: Brian Popow <38701097+brianpopow@users.noreply.github.com> Date: Fri, 6 May 2022 22:32:16 +0200 Subject: [PATCH] Update samples (#11420) --- ...soft.ML.OnnxRuntime.FasterRcnnSample.csproj | 6 +++--- .../Program.cs | 18 ++++++++++-------- ...soft.ML.OnnxRuntime.ResNet50v2Sample.csproj | 4 ++-- .../Program.cs | 17 ++++++++++------- 4 files changed, 25 insertions(+), 20 deletions(-) diff --git a/csharp/sample/Microsoft.ML.OnnxRuntime.FasterRcnnSample/Microsoft.ML.OnnxRuntime.FasterRcnnSample.csproj b/csharp/sample/Microsoft.ML.OnnxRuntime.FasterRcnnSample/Microsoft.ML.OnnxRuntime.FasterRcnnSample.csproj index afb68fe565..3d35de1dfc 100644 --- a/csharp/sample/Microsoft.ML.OnnxRuntime.FasterRcnnSample/Microsoft.ML.OnnxRuntime.FasterRcnnSample.csproj +++ b/csharp/sample/Microsoft.ML.OnnxRuntime.FasterRcnnSample/Microsoft.ML.OnnxRuntime.FasterRcnnSample.csproj @@ -7,9 +7,9 @@ - - - + + + \ No newline at end of file diff --git a/csharp/sample/Microsoft.ML.OnnxRuntime.FasterRcnnSample/Program.cs b/csharp/sample/Microsoft.ML.OnnxRuntime.FasterRcnnSample/Program.cs index df5b2bc8d1..b5545c01e2 100644 --- a/csharp/sample/Microsoft.ML.OnnxRuntime.FasterRcnnSample/Program.cs +++ b/csharp/sample/Microsoft.ML.OnnxRuntime.FasterRcnnSample/Program.cs @@ -4,7 +4,6 @@ using System.IO; using System.Linq; using Microsoft.ML.OnnxRuntime.Tensors; using SixLabors.ImageSharp; -using SixLabors.ImageSharp.Formats; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Drawing.Processing; @@ -33,16 +32,19 @@ namespace Microsoft.ML.OnnxRuntime.FasterRcnnSample var paddedWidth = (int)(Math.Ceiling(image.Width / 32f) * 32f); Tensor input = new DenseTensor(new[] { 3, paddedHeight, paddedWidth }); var mean = new[] { 102.9801f, 115.9465f, 122.7717f }; - for (int y = paddedHeight - image.Height; y < image.Height; y++) + image.ProcessPixelRows(accessor => { - Span pixelSpan = image.GetPixelRowSpan(y); - for (int x = paddedWidth - image.Width; x < image.Width; x++) + for (int y = paddedHeight - accessor.Height; y < accessor.Height; y++) { - input[0, y, x] = pixelSpan[x].B - mean[0]; - input[1, y, x] = pixelSpan[x].G - mean[1]; - input[2, y, x] = pixelSpan[x].R - mean[2]; + Span pixelSpan = accessor.GetRowSpan(y); + for (int x = paddedWidth - accessor.Width; x < accessor.Width; x++) + { + input[0, y, x] = pixelSpan[x].B - mean[0]; + input[1, y, x] = pixelSpan[x].G - mean[1]; + input[2, y, x] = pixelSpan[x].R - mean[2]; + } } - } + }); // Setup inputs and outputs var inputs = new List diff --git a/csharp/sample/Microsoft.ML.OnnxRuntime.ResNet50v2Sample/Microsoft.ML.OnnxRuntime.ResNet50v2Sample.csproj b/csharp/sample/Microsoft.ML.OnnxRuntime.ResNet50v2Sample/Microsoft.ML.OnnxRuntime.ResNet50v2Sample.csproj index 56e6271bbc..af8fa611a5 100644 --- a/csharp/sample/Microsoft.ML.OnnxRuntime.ResNet50v2Sample/Microsoft.ML.OnnxRuntime.ResNet50v2Sample.csproj +++ b/csharp/sample/Microsoft.ML.OnnxRuntime.ResNet50v2Sample/Microsoft.ML.OnnxRuntime.ResNet50v2Sample.csproj @@ -7,8 +7,8 @@ - - + + diff --git a/csharp/sample/Microsoft.ML.OnnxRuntime.ResNet50v2Sample/Program.cs b/csharp/sample/Microsoft.ML.OnnxRuntime.ResNet50v2Sample/Program.cs index 7339d1dbbd..374b63c697 100644 --- a/csharp/sample/Microsoft.ML.OnnxRuntime.ResNet50v2Sample/Program.cs +++ b/csharp/sample/Microsoft.ML.OnnxRuntime.ResNet50v2Sample/Program.cs @@ -33,16 +33,19 @@ namespace Microsoft.ML.OnnxRuntime.ResNet50v2Sample Tensor input = new DenseTensor(new[] { 1, 3, 224, 224 }); var mean = new[] { 0.485f, 0.456f, 0.406f }; var stddev = new[] { 0.229f, 0.224f, 0.225f }; - for (int y = 0; y < image.Height; y++) + image.ProcessPixelRows(accessor => { - Span pixelSpan = image.GetPixelRowSpan(y); - for (int x = 0; x < image.Width; x++) + for (int y = 0; y < accessor.Height; y++) { - input[0, 0, y, x] = ((pixelSpan[x].R / 255f) - mean[0]) / stddev[0]; - input[0, 1, y, x] = ((pixelSpan[x].G / 255f) - mean[1]) / stddev[1]; - input[0, 2, y, x] = ((pixelSpan[x].B / 255f) - mean[2]) / stddev[2]; + Span pixelSpan = accessor.GetRowSpan(y); + for (int x = 0; x < accessor.Width; x++) + { + input[0, 0, y, x] = ((pixelSpan[x].R / 255f) - mean[0]) / stddev[0]; + input[0, 1, y, x] = ((pixelSpan[x].G / 255f) - mean[1]) / stddev[1]; + input[0, 2, y, x] = ((pixelSpan[x].B / 255f) - mean[2]) / stddev[2]; + } } - } + }); // Setup inputs var inputs = new List