From f80f8f29e70a637f16849efd71aa5b45edccab0a Mon Sep 17 00:00:00 2001 From: andife Date: Mon, 6 Jun 2022 22:28:11 +0200 Subject: [PATCH] Update resnet50_csharp.md (#11514) changes due to https://github.com/microsoft/onnxruntime/pull/11420 --- docs/tutorials/resnet50_csharp.md | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/docs/tutorials/resnet50_csharp.md b/docs/tutorials/resnet50_csharp.md index e180c91612..38b17fcbe7 100644 --- a/docs/tutorials/resnet50_csharp.md +++ b/docs/tutorials/resnet50_csharp.md @@ -74,16 +74,19 @@ Next, we will preprocess the image according to the [requirements of the model]( 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]; + } } -} +}); ``` Here, we're creating a Tensor of the required size `(batch-size, channels, height, width)`, accessing the pixel values, preprocessing them and finally assigning them to the tensor at the appropriate indicies.