Comments (3)
Change
class ImageInputData
{
[ImageType(224, 224)]
public Bitmap Image { get; set; }
}
to
class ImageInputData
{
[ImageType(224, 224)]
public MLImage Image { get; set; }
}
from bitmaponnxprediction.
Thank you,
I have since reimplemented my code only using Microsoft.ML.OnnxRuntime and using Bitmaps with basic GDI functions for preprocessing, but it will be good to see how it should work with ML.NET.
With my changes, my code has become:
Microsoft.ML.OnnxRuntime.Tensors.Tensor<float> input = new Microsoft.ML.OnnxRuntime.Tensors.DenseTensor<float>(new[] { 1, 3, 720, 576 });
BitmapData bitmapData = originalImage.LockBits(new System.Drawing.Rectangle(0, 0, originalImage.Width, originalImage.Height), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
int stride = bitmapData.Stride;
IntPtr scan0 = bitmapData.Scan0;
unsafe
{
byte* ptr = (byte*)scan0;
for (int y = 0; y < originalImage.Height; y++)
{
for (int x = 0; x < originalImage.Width; x++)
{
int offset = y * stride + x * 3;
input[0, 0, y, x] = ptr[offset + 2] / 255.0f; // Red channel
input[0, 1, y, x] = ptr[offset + 1] / 255.0f; // Green channel
input[0, 2, y, x] = ptr[offset] / 255.0f; // Blue channel
}
}
}
originalImage.UnlockBits(bitmapData);
var inputs = new List<Microsoft.ML.OnnxRuntime.NamedOnnxValue>
{
Microsoft.ML.OnnxRuntime.NamedOnnxValue.CreateFromTensor("images", input)
};
var session = new Microsoft.ML.OnnxRuntime.InferenceSession(this.txtONNXFile.Text, sessionOptions);
Microsoft.ML.OnnxRuntime.IDisposableReadOnlyCollection<Microsoft.ML.OnnxRuntime.DisposableNamedOnnxValue> results = session.Run(inputs);
and it has worked very well so far, without any ML.NET problems, but I will try your solution and see whether it can solve the original issue.
from bitmaponnxprediction.
Updated the code. Thanks @MrBean2016
from bitmaponnxprediction.
Related Issues (2)
- Validation samples HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bitmaponnxprediction.