Update samples (#11420)

This commit is contained in:
Brian Popow 2022-05-06 22:32:16 +02:00 committed by GitHub
parent 2a90922f01
commit 3624f7c5a5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 20 deletions

View file

@ -7,9 +7,9 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.ML.OnnxRuntime" Version="1.9.0" />
<PackageReference Include="Sixlabors.ImageSharp" Version="1.0.3" />
<PackageReference Include="SixLabors.ImageSharp.Drawing" Version="1.0.0-beta11" />
<PackageReference Include="Microsoft.ML.OnnxRuntime" Version="1.11.0" />
<PackageReference Include="Sixlabors.ImageSharp" Version="2.1.1" />
<PackageReference Include="SixLabors.ImageSharp.Drawing" Version="1.0.0-beta14" />
</ItemGroup>
</Project>

View file

@ -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<float> input = new DenseTensor<float>(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<Rgb24> 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<Rgb24> 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<NamedOnnxValue>

View file

@ -7,8 +7,8 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.ML.OnnxRuntime" Version="1.9.0" />
<PackageReference Include="Sixlabors.ImageSharp" Version="1.0.3" />
<PackageReference Include="Microsoft.ML.OnnxRuntime" Version="1.11.0" />
<PackageReference Include="Sixlabors.ImageSharp" Version="2.1.1" />
</ItemGroup>
</Project>

View file

@ -33,16 +33,19 @@ namespace Microsoft.ML.OnnxRuntime.ResNet50v2Sample
Tensor<float> input = new DenseTensor<float>(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<Rgb24> 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<Rgb24> 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<NamedOnnxValue>