New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to downscale the pixel values in UWP App (C#) ? #22
Comments
Hi Krishna, |
Do you have more details on what your model expects? Like, what image formats and dimensions? I think you are saying that you have an image your model expects, to a dimension similar to squeezenet ? (1,3,224,244) and you also have the pixel data normalized to [0-1] vs. [0-255]. right? For downscaling to 244,244 you can use the normal VideoFrame::CopyToAsync() . For normalizing the tensor yourself, you would need to then tensorize that video frame into a TensorFloat object. the code would look something like this :
|
@LPBourret and @walrusmcd - Thanks for your responses I was able to access the pixel values. In Pytorch, the model has been trained on image pixel data where each pixel value was initially in the range [0,255] which is converted to [0,1] when the image data is loaded as a tensor in Pytorch (Essentially, every pixel value is divided by 255). I was able to perform this in the UWP app using a writeable bitmap (Inspiration - From this blog) But I observed that, these pixel values that are in the range [0,1] now can't be normalized with a certain Standard Deviation and Mean because if we do so, the pixel values will now be negative too but the byte storage format of pixels in UWP doesn't allow that. Is there any way to normalize the pixel values and store them in byte array ? |
Hi @walrusmcd I have a better understanding of the problem I have now. The following are the steps that I followed:
Can you please help me with passing the modified float values i.e (continuous values between 0 and 1) to the model ? Is this not possible with the windows.AI.machinelearning.preview ? I see that it is deprecated now. Is it possible with the pre-release version of windows.AI.machinelearning ? Thanks for your time.
|
using the Windows.AI.MachineLearning API (not preview) you would create a float array of the same shape as your model input requirement then populate it with normalized values from your SoftwareBitmap using the code you posted. You would then create a TensorFloat variable from that float array and bind it before evaluation (see TensorFloat.CreateFromArray() ) |
Hi @kchaitanyabandi
|
reopen if the issue is not resolved |
Update: the next coming release onnxruntime 1.7 adds support for pixel data normalized [0, 1] and [-1, 1]. |
- Add Conversion between Softwarebitmap to Float Tensor Reference: microsoft/Windows-Machine-Learning#22 https://docs.microsoft.com/en-us/windows/uwp/audio-video-camera/imaging
Hi,
I built a UWP App based on the Squeeze Net example provided in the repository (C#) that uses a Deep Learning model (ONNX) for image classification. I have built the deep learning model in PyTorch where the pixel values of the image have been scaled down from the range [0, 255] to [0, 1] and then normalized with channel wise (RGB) standard deviation and mean. So, this model expects the pixel values other than [0, 255] range.
But in the UWP App, I'm unable to perform this downscaling of the pixel values before binding the inputs to the model. I have searched the SoftwareBitmap class but couldn't find a way to perform this downscaling operation. Any help would be very very appreciated.
I need this operation somewhere in between these lines of code.
`
Thanks
Krishna
The text was updated successfully, but these errors were encountered: