mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-07-16 18:31:27 +00:00
Update resnet50_csharp.md (#11514)
changes due to https://github.com/microsoft/onnxruntime/pull/11420
This commit is contained in:
parent
4df8d60e72
commit
f80f8f29e7
1 changed files with 10 additions and 7 deletions
|
|
@ -74,16 +74,19 @@ Next, we will preprocess the image according to the [requirements of the model](
|
|||
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];
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
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.
|
||||
|
|
|
|||
Loading…
Reference in a new issue