onnxruntime 可以加速模型的部署,同时可以跨框架,例如
源码项目位置:https://github.com/microsoft/onnxruntime
里面有一些依赖,这里直接打包,提供百度网盘的下载:
链接:https://pan.baidu.com/s/1sTryvfX0sLKIoHm8aMm4Sg
提取码:be9o
解压后:
执行命令:
git init
git submodule sync
git submodule update --init --recursive
1.然后进行编译:使用CUDA
./build.sh --skip_tests --use_cuda --config Release --build_shared_lib --parallel --cuda_home /usr/local/cuda --cudnn_home /usr/local/cuda
2.如果不使用CUDA,用默认的CPU
./build.sh --skip_tests --config Release --build_shared_lib --parallel
3.使用TensorRT:
./build.sh --build_shared_lib --skip_tests --config Release --use_cuda --cudnn_home /usr/local/cuda/ --cuda_home /usr/local/cuda --use_tensorrt --tensorrt_home /home/TensorRT-version/
安装成功。
因为微软没用提供find_package()的用法,所以这里CMAKE写法:
#onnxruntime
set(ONNXRUNTIME_ROOT_PATH your_path_to_onnxruntime_source_dir)
set(ONNXRUNTIME_INCLUDE_DIRS ${ONNXRUNTIME_ROOT_PATH}/include/onnxruntime
${ONNXRUNTIME_ROOT_PATH}/onnxruntime
${ONNXRUNTIME_ROOT_PATH}/include/onnxruntime/core/session/)
set(ONNXRUNTIME_LIB ${ONNXRUNTIME_ROOT_PATH}/build/Linux/Release/libonnxruntime.so)
include_directories(${ONNXRUNTIME_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME} ${ONNXRUNTIME_LIB})
在C++里面头文件:
#include <core/session/onnxruntime_cxx_api.h>
#include <core/providers/cuda/cuda_provider_factory.h>
#include <core/session/onnxruntime_c_api.h>
另外可以编译tensorRT版本的,加速模型推理。