输入参数类型问题
run函数的参数列表如下:
SessionImpl::Run(const Ort::RunOptions&, const char* const*, const Ort::Value*, size_t, const char* const*, Ort::Value*, size_t)
注意需要输入输出的参数名字形式是const char* const*
方式1 const char* 数组
const char* input_name[1] = {"xxx"};
const char* output_name[1] = {"xxx"};
vector<Value> ort_outputs = ort_session->Run(RunOptions{ nullptr }, input_name, &input_tensor_, 1, output_name, output_names.size());
方式2 vector<const char*>
std::vector<std::string> inputNames = {"x"};
std::vector<const char*> inputTensorNames(1, nullptr);
std::transform(std::begin(inputNames), std::end(inputNames), std::begin(inputTensorNames),[&](const std::string& str) { return str.c_str(); });
vector<Value> ort_outputs = ort_session->Run(RunOptions{ nullptr }, inputTensorNames.data(), &input_tensor_, 1, output_name, output_names.size());
方式3 const char* const*
const char* s1 = "x";
const char* s2 = "softmax_5.tmp_0";const char* const arr1[] = {s1};
const char* const arr2[] = {s2};const char* const* ptr1 = arr1;
const char* const* ptr2 = arr2;vector<Value> ort_outputs = ort_session->Run(RunOptions{ nullptr }, ptr1, &input_tensor_, 1, ptr2, output_names.size());