From bfabb388f5ed131015466ee2841b5df7aef20645 Mon Sep 17 00:00:00 2001 From: andife Date: Mon, 6 Jun 2022 22:28:32 +0200 Subject: [PATCH] Update fasterrcnn_csharp.md (#11513) adapted according to https://github.com/microsoft/onnxruntime/pull/11420 --- docs/tutorials/fasterrcnn_csharp.md | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/docs/tutorials/fasterrcnn_csharp.md b/docs/tutorials/fasterrcnn_csharp.md index 85482d2665..1df0cefa9c 100644 --- a/docs/tutorials/fasterrcnn_csharp.md +++ b/docs/tutorials/fasterrcnn_csharp.md @@ -67,16 +67,19 @@ var paddedHeight = (int)(Math.Ceiling(image.Height / 32f) * 32f); 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]; + } } -} +}); ``` Here, we're creating a Tensor of the required size `(channels, paddedHeight, paddedWidth)`, accessing the pixel values, preprocessing them and finally assigning them to the tensor at the appropriate indicies. @@ -180,4 +183,4 @@ dotnet run ~/Downloads/FasterRCNN-10.onnx ~/Downloads/demo.jpg ~/Downloads/out.j detects the following objects in the image: -![](/images/out.jpg) \ No newline at end of file +![](/images/out.jpg)