C++ onnxruntime 报错Ort::Exception: tried creating tensor with negative value in shape

环境 win10 onnxruntime 1.15.1

在使用yolov5 进行推理部署时,一直报错Ort::Exception: 读取内存冲突等
,后分析发现,是声明的 Ort相关变量都是局部变量,需要修改成全局变量,如下所示,我是在.h文件中声明的。
Env env = Env(ORT_LOGGING_LEVEL_ERROR, “yolov5s”);
Ort::Session* ort_session = nullptr;
SessionOptions sessionOptions = SessionOptions();
vector<const char* > input_names;
vector<const char* > output_names;
vector<vector<int64_t>> input_node_dims; // >=1 outputs
vector<vector<int64_t>> output_node_dims; // >=1 outputs
std::vector In_AllocatedStringPtr;
std::vector Out_AllocatedStringPtr;

还有一个问题就是  onnxruntime 在1.12版本以后 不能使用GetInputName,需要改成GetInputNameAllocated,并且 需要使用
.h内
    std::vector<AllocatedStringPtr> In_AllocatedStringPtr;
std::vector<AllocatedStringPtr> Out_AllocatedStringPtr; 来获取相关信息,

.cpp内
AllocatorWithDefaultOptions allocator;
In_AllocatedStringPtr.push_back(ort_session->GetInputNameAllocated(i, allocator));
input_names.push_back(In_AllocatedStringPtr.at(i).get());

AllocatorWithDefaultOptions allocator;
Out_AllocatedStringPtr.push_back(ort_session->GetOutputNameAllocated(i, allocator));
output_names.push_back(Out_AllocatedStringPtr.at(i).get());

  • 5
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值