用onnxruntime跑推理的时候发现报错:
2024-07-03 10:37:55.516340683 [E:onnxruntime:Default, provider_bridge_ort.cc:1532 TryGetProviderInfo_TensorRT] /onnxruntime_src/onnxruntime/core/session/provider_bridge_ort.cc:1209 onnxruntime::Provider& onnxruntime::ProviderLibrary::Get() [ONNXRuntimeError] : 1 : FAIL : Failed to load library libonnxruntime_providers_tensorrt.so with error: libnvinfer.so.8: cannot open shared object file: No such file or directory
搜了网上的教程没用,检查了一下 libnvinfer.so.8
是否存在:
updatedb
locate libnvinfer.so.8
没有该文件,又检查:
locate libnvinfer.so
发现了 xxx/site-packages/tensorrt_libs/libnvinfer.so.10
,所以可以猜测是 Python 的 tensorrt 库的版本问题。检查版本发现确实为 tensorrt-10.0.1
。降级到 tensorrt-8.6.1
:
pip install tensorrt==8.6.1
重新检查 libnvinfer.so
:
updatedb
locate libnvinfer.so
找到了 xxx/site-packages/tensorrt_libs/libnvinfer.so.8
。但重新运行程序发现报错还是没有解决,根据网上资料将路径加入 LD_LIBRARY_PATH
:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:xxx/site-packages/tensorrt_libs
# 注意替换成自己locate到的路径
重新运行,报错解决。