Hellow!
I'm very new to Microsoft ML ONNX.
Making GUI using 'Visual studio 2019', 'Windows Forms App' with '.NET framework(C# 7.3 ver)'
I use python sklearn to make simple KNN, then export to ONNX form.
MS VS Forms are receiving the Sensor data from DSP through serial communication, then the program uses sensor data to make an input tensor for ONNX InferenceSession(1*3 float dense tensor).
My ONNX predict code looks like this.
private void Predict()
{
string Filepath = "C:\\Users\\lee5w\\source\\repos\\Rehabilitation\\Rehabilitation\\Resource\\KNN.onnx";
InferenceSession session = new InferenceSession(Filepath);
DenseTensor<float> T1;
float[,] Predict_input = new float[1, 3];
Predict_input[0, 0] = (float)value[5];
Predict_input[0, 1] = (float)value[6];
Predict_input[0, 2] = (float)value[7];
RMS1.Text = "RMS1: " + value[5].ToString();
RMS2.Text = "RMS2: " + value[6].ToString();
RMS3.Text = "RMS3: " + value[7].ToString();
T1 = Predict_input.ToTensor();
var inputMeta = session.InputMetadata;
var outputMeta = session.OutputMetadata;
var inputs1 = new List<NamedOnnxValue>();
foreach (var name in inputMeta.Keys)
{
inputs1.Add(NamedOnnxValue.CreateFromTensor<float>(name, T1));
}
try
{
//IDisposableReadOnlyCollection<DisposableNamedOnnxValue> Run(IReadOnlyCollection<NamedOnnxValue> inputs, IReadOnlyCollection<string> desiredOutputNodes);
var results = session.Run(inputs1); //IDisposableReadOnlyCollection<DisposableNamedOnnxValue>
// dump the results
var inferenceResult = results.ToList()[0];
var inferenceResult_Value = inferenceResult.Value;
var Output = session.Run(inputs1).ToList().First().AsEnumerable<NamedOnnxValue>();
}
catch (Exception error)
{
MessageBox.Show(error.Message);
}
}
At the debug state I can find 'result.ToList()[0]' was the output_label. So I try to use the value of 'result.ToList()[0]', but I can't turn it into any different shape.
Image of visual studio debug values
I try tensor form, list form, dictionary form but they return 'null'. When I use .ToString() it return 'Microsoft.ML.OnnxRuntime.Tensors.DenseTensor'
Is there anyone who knows how to make the value of 'Object {Microsoft.ML.OnnxRuntime.Tensors.DenseTensor} ' into string or int?
Inside of Object {Microsoft.ML.OnnxRuntime.Tensors.DenseTensor}
I just find my own answer.
It was something like this.
var Test = results.ToList()[0].AsTensor<long>().ToArray<long>()[0].ToString();