mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-07-16 18:31:27 +00:00
Update fasterrcnn_csharp.md (#11513)
adapted according to https://github.com/microsoft/onnxruntime/pull/11420
This commit is contained in:
parent
f80f8f29e7
commit
bfabb388f5
1 changed files with 11 additions and 8 deletions
|
|
@ -67,16 +67,19 @@ var paddedHeight = (int)(Math.Ceiling(image.Height / 32f) * 32f);
|
|||
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];
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
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:
|
||||
|
||||

|
||||

|
||||
|
|
|
|||
Loading…
Reference in a new issue