ONNX加载模型问题总结
输入参数类型问题
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 ort_outputs = ort_session->Run(RunOptions{ nullptr }, input_name, &input_tensor_, 1, output_name, output_names.size());
方式2 vector
std::vector inputNames = {"x"}; std::vector inputTensorNames(1, nullptr); std::transform(std::begin(inputNames), std::end(inputNames), std::begin(inputTensorNames), [&](const std::string& str) { return str.c_str(); }); vector 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 ort_outputs = ort_session->Run(RunOptions{ nullptr }, ptr1, &input_tensor_, 1, ptr2, output_names.size());
文章版权声明:除非注明,否则均为主机测评原创文章,转载或复制请以超链接形式并注明出处。