首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在Ubuntu20.04 (C++ API)上设置

在Ubuntu20.04 (C++ API)上设置
EN

Stack Overflow用户
提问于 2020-08-14 22:03:13
回答 2查看 5.8K关注 0票数 3

我目前正试图让我的图像处理程序在Ubuntu上工作(来自windows)。

我已经成功地构建并链接了OpenCV和Boost库来使用我的cpp程序,但是还没有找到任何关于在Ubuntu20.04上设置Onnx C++的说明,除了对特定的Visual项目使用NuGet包管理器使用以下命令以外:

代码语言:javascript
运行
复制
Install-Package Microsoft.ML.OnnxRuntime -Version 1.4.0

在Windows上,我只需要使用NuGet包管理器来下载给定visual项目的库。在Ubuntu上使用NuGet似乎可以做到这一点,但我想知道我是否可以更“手动”地完成它,比如boost和OpenCV的构建和安装。谢谢!

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2020-08-14 23:05:56

对于默认的CPU版本,可以下载tgz文件这里

对于其他无法作为tgz或NuGet (例如TensorRT)使用的ONNX运行时,您可以在本地构建它们:

代码语言:javascript
运行
复制
./build.sh --cudnn_home <path to cuDNN e.g. /usr/lib/x86_64-linux-gnu/> --cuda_home <path to folder for CUDA e.g. /usr/local/cuda> --use_tensorrt --tensorrt_home <path to TensorRT home>

更多的说明可以在构建ONNX运行时找到。

票数 1
EN

Stack Overflow用户

发布于 2021-03-05 14:41:30

在Linux上安装NuGet on运行时发行版

在Ubuntu 20.04上测试

对于通过NuGet提供的into运行时的新版本,我采用了以下工作流程:下载发行版(这里是1.7.0,但您可以相应地更新链接),并将其安装到~/.local/中。对于全局(系统范围)安装,您可以将文件放在/usr/local/下的相应文件夹中。

代码语言:javascript
运行
复制
mkdir /tmp/onnxInstall
cd /tmp/onnxInstall
wget -O onnx_archive.nupkg https://www.nuget.org/api/v2/package/Microsoft.ML.OnnxRuntime/1.7.0
unzip onnx_archive.nupkg
cp runtimes/linux-x64/native/libonnxruntime.so ~/.local/lib/
cp -r build/native/include/ ~/.local/include/onnxruntime/

Cmake

现在,如果您希望能够从您的Cmake包中find_package(onnxruntime),我建议您将我自己创建的onnx文件放在~/.local/share/cmake/onnxruntime中。这些档案是:

cat ~/.local/share/cmake/onnxruntime/onnxruntimeVersion.cmake

代码语言:javascript
运行
复制
# Custom cmake version file by jcarius

set(PACKAGE_VERSION "1.7.0")

# Check whether the requested PACKAGE_FIND_VERSION is compatible
if("${PACKAGE_VERSION}" VERSION_LESS "${PACKAGE_FIND_VERSION}")
  set(PACKAGE_VERSION_COMPATIBLE FALSE)
else()
  set(PACKAGE_VERSION_COMPATIBLE TRUE)
  if("${PACKAGE_VERSION}" VERSION_EQUAL "${PACKAGE_FIND_VERSION}")
    set(PACKAGE_VERSION_EXACT TRUE)
  endif()
endif()

cat ~/.local/share/cmake/onnxruntime/onnxruntimeConfig.cmake

代码语言:javascript
运行
复制
# Custom cmake config file by jcarius to enable find_package(onnxruntime) without modifying LIBRARY_PATH and LD_LIBRARY_PATH
#
# This will define the following variables:
#   onnxruntime_FOUND        -- True if the system has the onnxruntime library
#   onnxruntime_INCLUDE_DIRS -- The include directories for onnxruntime
#   onnxruntime_LIBRARIES    -- Libraries to link against
#   onnxruntime_CXX_FLAGS    -- Additional (required) compiler flags

include(FindPackageHandleStandardArgs)

# Assume we are in <install-prefix>/share/cmake/onnxruntime/onnxruntimeConfig.cmake
get_filename_component(CMAKE_CURRENT_LIST_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
get_filename_component(onnxruntime_INSTALL_PREFIX "${CMAKE_CURRENT_LIST_DIR}/../../../" ABSOLUTE)

set(onnxruntime_INCLUDE_DIRS ${onnxruntime_INSTALL_PREFIX}/include)
set(onnxruntime_LIBRARIES onnxruntime)
set(onnxruntime_CXX_FLAGS "") # no flags needed


find_library(onnxruntime_LIBRARY onnxruntime
    PATHS "${onnxruntime_INSTALL_PREFIX}/lib"
)

add_library(onnxruntime SHARED IMPORTED)
set_property(TARGET onnxruntime PROPERTY IMPORTED_LOCATION "${onnxruntime_LIBRARY}")
set_property(TARGET onnxruntime PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${onnxruntime_INCLUDE_DIRS}")
set_property(TARGET onnxruntime PROPERTY INTERFACE_COMPILE_OPTIONS "${onnxruntime_CXX_FLAGS}")

find_package_handle_standard_args(onnxruntime DEFAULT_MSG onnxruntime_LIBRARY onnxruntime_INCLUDE_DIRS)
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63420533

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档