-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Tensor Creation from data #4528
Comments
You can do |
@pranavsharma Thank you. I am using one of the examples as template. in
what is the difference between const int64_t* shape, size_t shape_len? |
How can I check the data in created Tensor ? |
4 is the number of elements (dimensions) in the shape array pointed to by the 'shape' ptr. Given that CreateTensor is a C API and accepts just a ptr to the shape, it has no idea how many elements (dimensions) the shape array contains. This is why it accepts shape_len as well. |
@pranavsharma, Thank you. My model has input shape {1, 2}.
where inp_data is array {a, b} (a and b are float, not 2D), mdp.TensorSize[i] = 2; on the next step I am checking the input_tensor shape with respect to the model input:
output is:
on the next step I am converting the Tensor to the vector:
floatarr shape is {0, 2}. It is match with inp_data. finally, I am trying to run the model:
where mdp.InputLayerName.data() - array with input names {"data_in"}; mdp.Ninp - number of inputs (1); mdp.OututLayerName.data() - array with output names {"label", "label_prob"}; mdp.OututLayerName.size() - number of outputs (2); The code passes the compilation but throw Exception related with access to the memory when run.
Debugger refers to this line
I suppose that main problem can be related with both: tensor structure or creating output tensor. Or I am doing in general something wrong? |
@TratsiakY I have submitted a PR here that will make it easier to check data in a tensor. I had the same challenges as you. It will allow you to access tensor data similar to how OpenCV Mat's Not sure why but in my experience, it does seem to take an exceptional amount of time for PRs to get reviewed and merged into master. @pranavsharma is there someone dedicated to working on the C++ API that I should ping when requesting a review? |
@TratsiakY A couple other things that are not very apparent in the C++ documentation.
If you changed the values of |
Looks ok. What status message is returned? I can't follow this "Вызвано исключение по адресу 0x00007FFEF1E5A839 в ClassificatorCaller.exe: исключение Microsoft C++: std::logic_error по адресу памяти 0x0000009B356FBDA0." |
@jgbradley1, @pranavsharma thank you. Seems thatwe have a bug, probably . I used the squeezenet example with minor modification for my model (input and output layers quantity and names). The error was the same, as was mentioned before : The exception on adress 0x00007FFEF1E5A839 was called in MyProject.exe: exception Microsoft C++: std::logic_error on memory address 0x0000009B356FBDA0 (the memory cells addresses for different runs were different) finally, I tryed to get the prediction only for one output layer. I was surprised, because the code was passed the compilation and worked properly.
Meanwhile, the code pass the compilation but fall at run if I try to get the array with predictions output. The error occurs in place where the output tensor is created:
|
I've found yet one strange moment. |
@pranavsharma, @jgbradley1, Please, find attached .cpp files and onnx model for play and repeat the error. |
@TratsiakY you must ensure the environment instance outlives the session. In your example, the env instance gets destructed at the end of the PredictWithONNXModel constructor. If you move the environment to a class member, it should work just fine. |
Will making env a static variable work? I have a similar issue in which the prediction for the same data for the very first time is not correct but it works fine for second time and further. |
Hi.
I've exported my classificator to .onnx and have checked it in python with onnxruntime. All works perfect.
So, I am trying to run my model in c++ now but, unfortunatelly, I haven't got an enought experience in c++. I've studied examples and try to write my own code, but the moment with transform of vector to tensor is not clear for me.
in the case of vector {m}, where m is a number of elements the code below pass the compilation
(meanwhile, I am not sure that used dims for init_data is correct, but I am not about that).
The main problem is:
How should be written the CreateTensor() in the case of vector{m, n}, where m - rows, n - cols (for example for, vector<vector> init_data = {{a1, b1}, {a, b} })?
The text was updated successfully, but these errors were encountered: