You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I see ImageSharp being used as the backbone for AI image inference more often than not.
In most cases the process involves loading an image with ImageSharp, copying the pixels to a tensor, and running the model.
The tricky interop thing is the "copy pixels to a tensor", seeng how people is doing it , tells me there's a lot of room for improvement.
Preparing an image for a tensor involves two steps:
1- rescale the image to fit into the tensor, sometimes preserving aspect ratio, sometimes not.
2- convert pixels to float, and then apply a std-mean expansion.
Now, the second issue is that the destination is usually a specific data type like the tensors provided by OnnxRuntime or other inference engines.
Microsoft has recently introduced System.Numerics.Tensors.TensorSpan<T> which is readily available, and can provide a middle ground between ImageSharp and any third party inference engine.
So my proposal is to and an extension API that looks like this:
Image.CopyPixelsToTensor(TensorSpan dest, ...)
where additional parameters would tell whether to perform automatic rescaling/fitting, and the std-mean value expasion (which is basically a MAD operation applied to the pixel values)
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
I see ImageSharp being used as the backbone for AI image inference more often than not.
In most cases the process involves loading an image with ImageSharp, copying the pixels to a tensor, and running the model.
The tricky interop thing is the "copy pixels to a tensor", seeng how people is doing it , tells me there's a lot of room for improvement.
Preparing an image for a tensor involves two steps:
1- rescale the image to fit into the tensor, sometimes preserving aspect ratio, sometimes not.
2- convert pixels to float, and then apply a std-mean expansion.
Now, the second issue is that the destination is usually a specific data type like the tensors provided by OnnxRuntime or other inference engines.
Microsoft has recently introduced
System.Numerics.Tensors.TensorSpan<T>
which is readily available, and can provide a middle ground between ImageSharp and any third party inference engine.So my proposal is to and an extension API that looks like this:
Image.CopyPixelsToTensor(TensorSpan dest, ...)
where additional parameters would tell whether to perform automatic rescaling/fitting, and the std-mean value expasion (which is basically a MAD operation applied to the pixel values)
Beta Was this translation helpful? Give feedback.
All reactions