“GetInputName“: 不是 “Ort::Session“ 的成员

项目场景:

使用C++和ONNXruntime部署深度学习模型


问题描述

作者在尝试使用onnxruntime和C++部署深度学习模型推理的时候,按照官网的文档对于Ort::Session::Run的定义(如下),需要获得模型输入层与输出层的名字。

std::vector< Value > Ort::Session::Run	(	
                const RunOptions & 	run_options,
                const char *const * input_names,
                const Value * input_values,
                size_t 	input_count,
                const char *const * 	output_names,
                size_t 	output_count 
                )		

于是网上大部分的代码使用的方法是使用GetInputName()与GetOutputName()方法获得上述内容。 

但是在执行时会报错,如标题。


原因分析:

我继续查阅了官网对于这两个方法的描述

 可以发现这两个方法已经被弃用并替换成了GetInputNameAllocated()GetOutputNameAllocated()


解决方案:

以我的代码为例:

原代码如下:

vector<char*> input_names;
vector<char*> output_names;
vector<vector<int64_t>> input_node_dims;
vector<vector<int64_t>> output_node_dims;
for (int i = 0; i < numInputNodes; i++)
{
	input_names.push_back(ort_session->GetInputName(i, allocator));
	Ort::TypeInfo input_type_info = ort_session->GetInputTypeInfo(i);
	auto input_tensor_info = input_type_info.GetTensorTypeAndShapeInfo();
	auto input_dims = input_tensor_info.GetShape();
	input_node_dims.push_back(input_dims);
}
for (int i = 0; i < numOutputNodes; i++)
{
	output_names.push_back(ort_session->GetOutputName(i, allocator));
	Ort::TypeInfo output_type_info = ort_session->GetOutputTypeInfo(i);
	auto output_tensor_info = output_type_info.GetTensorTypeAndShapeInfo();
	auto output_dims = output_tensor_info.GetShape();
	output_node_dims.push_back(output_dims);
}

我的选择是将GetInputName()与GetOutputName()所在的行改为如下:

AllocatedStringPtr input_name_Ptr = ort_session->GetInputNameAllocated(i, allocator);
input_names.push_back(input_name_Ptr.get());

AllocatedStringPtr output_name_Ptr= ort_session->GetInputNameAllocated(i, allocator);
output_names.push_back(output_name_Ptr.get());

即可成功运行。

  • 26
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 18
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 18
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

超爱苦力怕

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值