Efficient RGB Image to Tensor in dotnet #10634
Replies: 4 comments 4 replies
-
In my case, I am doing something like that, but my code needs to run in realtime because the image comes from a camera. Furthermore, I need to crop a rotated region of the source image, which makes things even more complicated. @skywalkerisnull I am using OpenCVSharp just for the image processing, which is a bit overkill to use such a huge library just for cropping and rotating. Given that a large amount of users are using OnnxRuntime for artificial vision, it would be nice to have some helper classes to deal with images. |
Beta Was this translation helpful? Give feedback.
-
@skywalkerisnull you can make your code even more faster by casting to System.Numerics.Vector3 instead of float, because the pixel processing is done in one shot. Anyway, I cannot use ImageSharp in my use case, because ImageSharp's image rotation is quite slow and I need processing 30 images per second in a low end intel i3 processor, with as little memory allocation as possible. My current image processing pipeline lets me take the captured image from the device, represented as an IntPtr, and crop a rotated region directly into the tensors, without creating intermediate images. But I think for cases like this, the ideal solution would be to have a library able to process images in the same context that is running the onnx model. I mean, if for example we're using the GPU to run the onnx model, it would be desirable to be able to upload the current image to the GPU (maybe via DirectX or Vulkan buffers), do the image processing using GPU, which is probably way faster than any trick we can find, and then fill the tensors in the GPU itself. I don't know if such a thing is being considered in the OnnxRuntine APIs |
Beta Was this translation helpful? Give feedback.
-
related issues to exposing API: other related issues: |
Beta Was this translation helpful? Give feedback.
-
@skywalkerisnull could U add [c#] in front of your title of discussion instead of using dotnet |
Beta Was this translation helpful? Give feedback.
-
Hello everyone,
We are trying to find a more efficient method of converting the RGB values from an image, into a tensor. The current process that we are using is modeled on the sample code: https://github.com/microsoft/onnxruntime-csharp-cv-template/blob/af9061afe3077b2b7b137bf2d280541ecc316c4d/utils/ImageHelper.cs#L29
or more specifically, our variation:
We are building batches that may be up to 500 images and can run the inference in less than 200ms for this batch on a Nvidia V100 (non optimized model). However, creating the batch is more than 11 seconds per batch. i.e. we would need approx. 55 threads creating the batches to keep up with the GPU throughput.
I found a discussion in the ImageSharp discussions that I jumped onto and were discussing this: SixLabors/ImageSharp#1955
What methods have other people used, or even other libraries that may be able to move the RGB to the tensor batch in an efficient way?
Beta Was this translation helpful? Give feedback.
All reactions