microsoft/onnxruntime

[C++ API] How to do onnxruntime inference with multi input?

kai06046 opened this issue · 6 comments

I saw an example in c# here, but cannot find an example that shows how to do this in c++. Can anyone kindly provide some advice?

Could you take a look at the following and close the issue if it helps ?

#1323 #2143

Thanks.

Closing as this is a duplicated issue. Please use the answers in the referenced issues above. Re-open this issue if it doesn't help you.

I actually got 2 input nodes that have bool and float type.

Number of inputs = 2
Input 0 : name=flag:0
Input 0 : type=9
Input 0 : num_dims=0
Input 1 : name=images:0
Input 1 : type=1
Input 1 : num_dims=4
Input 1 : dim 0=-1
Input 1 : dim 1=120
Input 1 : dim 2=120
Input 1 : dim 3=3

Refer to this comment, I was able to create input tensors with multi input and different types, below is the related code:

bool* input_bool_tensor_values = {false};
Ort::Value input_bool = Ort::Value::CreateTensor<bool>(memory_info, input_bool_tensor_values, 1, input_1_node_dims.data(), 0);
Ort::Value input_tensor = Ort::Value::CreateTensor<float>(memory_info, input_tensor_values.data(), input_tensor_values.size(), input_node_dims.data(), 4);
Ort::Value* input_tensors[2];
input_tensors[0] = &input_bool;
input_tensors[1] = &input_tensor;

auto output_tensors = session.Run(Ort::RunOptions{nullptr},
   input_node_names.data(), 
  // (const Ort::Value*)&input_tensors, 
   &input_tensors, 
   2, 
   output_node_names.data(),
   1);

An error C2664: 'void Ort::Ses sion::Run(const Ort::RunOptions &,const char *const *,const Ort::Value *,size_t,const char *const *,Ort::Value *,size_t )': cannot convert argument 3 from 'Ort::Value *(*)[2]' to 'const Ort::Value *' came out.
I also tried Ort::Value *input_tensors = new(Ort::Value) * 2; but got this error C2512: 'Ort::Value': no appropriate default constructor available.
I am not very familiar with C++, any advice?

Found this example and it work.