先看一下onnxruntime 官网写了啥

PS:如果包安装了之后一直用不了提示Can‘t find dependent libraries可以去这里的链接看一看,可能就是你Visual C++ 2019没装的问题

官网写的大概就是先定义一个env一个 session然后再写一个包含{名字:OnnxTensor}的字典,然后把字典放入session的run方法中,现在的问题是OnnxTensor是啥

看看OnnxTensor的文档怎么写的

PS:文档中还写了很多很多种的方法,建议去看看,这里是因为我把图片归一化后转换成了FloatBuffer类型的所以用这个。

 可以用这个创建一个OnnxTensor 需要输入的参数分别是,env(上面你创建的),floatBuffer(你的一维展开的数据),shape(你的数据将要变成什么形状的OnnxTensor)

输出名称和输入名称可以用session.getInputNames()和session.getOutputNames()来查看

然后在results拿到之后

//OutputNames为你的输出名称
Optional<OnnxValue> results = results.get("OutputNames");
results .isPresent()
OnnxValue onnxValue = results .get();
TensorInfo tensorInfo = (TensorInfo) onnxValue.getInfo();

 //获得的数据的形状

long[] outputShape_Long = tensorInfo.getShape();

//获得的数据,onnxValue.getValue()只是一个数据地址如果直接输出将会是这种格式的        
[[[F@4459eb14。所以需要一个同形状同类型的来接收一下,
float[][][] outputValue_Long = (float[][][]) onnxValue.getValue();

/*

现在你已经拿到了数据了可以对数据进行自己的处理了

*/

 

GitHub 加速计划 / on / onnxruntime
25
3
下载
microsoft/onnxruntime: 是一个用于运行各种机器学习模型的开源库。适合对机器学习和深度学习有兴趣的人,特别是在开发和部署机器学习模型时需要处理各种不同框架和算子的人。特点是支持多种机器学习框架和算子,包括 TensorFlow、PyTorch、Caffe 等,具有高性能和广泛的兼容性。
最近提交(Master分支:7 个月前 )
c5d1416e 8 小时前
aa87e34e ### Description WebGPU, VitisAI, and DML are missing from the list. ### Motivation and Context If users misspell a provider name this error should be showing them the full possibilities. Leaving one out will lead to confusion. I noticed it when testing new providers in GenAI that the error message was not up to date. 9 小时前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐