[亲测有效]VS2019/Ubuntu配置Onnxruntime、Opencv

文章目录

  • [windows] VS配置Onnxruntime
  • [windows] VS配置Opencv
  • [ubuntu] CPP配置Onnxruntime

[windows] VS配置Onnxruntime

参考: https://blog.csdn.net/weixin_42795611/article/details/107338541
亲测:
0. 首先确定cudnn的版本

nvcc --version
C:\Users\yx_computer> nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2020 NVIDIA Corporation
Built on Tue_Sep_15_19:12:04_Pacific_Daylight_Time_2020
Cuda compilation tools, release 11.1, V11.1.74
Build cuda_11.1.relgpu_drvr455TC455_06.29069683_0

1. 下载Onnxruntime:
当cudnn的版本为10.*时,选择下面链接下载
https://github.com/microsoft/onnxruntime/releases/tag/v1.3.0
当cudnn的版本为11.*时,选择下面链接下载
https://github.com/microsoft/onnxruntime/releases/tag/v1.9.0[亲测有效]VS2019/Ubuntu配置Onnxruntime、Opencv_第1张图片
注:当出现dlerror:cublas64_10.dll not found类似的错误,有可能是cudnn的版本号与onnxruntime不对应。
这里有所有的onnxruntime下载链接:https://github.com/microsoft/onnxruntime/tags

2. 打开vs新建项目——>右击点击属性——>C/C++属性,添加解压后的include文件路径,注意配置平台的选择。
下图红线框选择x64,配置时,选择相对应选项。(下载onnxruntime的安装包时,也要注意版本的下载)
[亲测有效]VS2019/Ubuntu配置Onnxruntime、Opencv_第2张图片[亲测有效]VS2019/Ubuntu配置Onnxruntime、Opencv_第3张图片
3. 点击链接器——>附加库目录,添加解压后的lib文件路径。
[亲测有效]VS2019/Ubuntu配置Onnxruntime、Opencv_第4张图片
4. 点击输入——>附加依赖项,将onnxruntime.lib添加进去。
[亲测有效]VS2019/Ubuntu配置Onnxruntime、Opencv_第5张图片
5. 先运行一个简单程序,生成Debug文件

#include   

int main()
{
	printf("hello, onnx!\n");
	system("pause");
	return 0;
}

选择平台x64
[亲测有效]VS2019/Ubuntu配置Onnxruntime、Opencv_第6张图片

6. 将onnxruntime.dll放入到项目的Debug或Release下
注意: onnxruntime.dll是放在含有.exe的Debug文件路径下。
[亲测有效]VS2019/Ubuntu配置Onnxruntime、Opencv_第7张图片

7. 验证是否成功

#include   
#include 


int main()
{
	printf("hello, onnx!\n");
	system("pause");
	return 0;
}

[亲测有效]VS2019/Ubuntu配置Onnxruntime、Opencv_第8张图片

[windows] VS配置Opencv

参考:https://blog.csdn.net/xgocn/article/details/104170088

[ubuntu] CPP配置Onnxruntime

  • 在Ubuntu中安装c++(安装则跳过)
    参考:https://blog.csdn.net/W1995S/article/details/117876875
    1. 查看gcc、g++是否安装

    gcc --version
    g++ --version
    

    2.安装

    sudo apt-get install gcc
    sudo apt-get install g++
    
    或指定版本:8
    sudo apt-get install gcc-8
    sudo apt-get install g++-8
    

    报错1:

    E: Could not get lock /var/lib/dpkg/lock-frontend - open (11: Resource temporarily unavialable)
    E: Unable to acquire the dpkg fronted lock (/var/lib/dpkg/lock-frontend), is another process using it?
    

    解决:

    sudo rm -rf /var/cache/apt/archives/lock-frontend
    sudo  rm -rf /var/lib/dpkg/lock-frontend
    

    报错2:

    E: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable)
    E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?
    

    解决:

    sudo rm /var/lib/dpkg/lock
    sudo dpkg --configure -a
    

    3.创建cpp文件
    创建项目目录cppdemo,用于学习创建第一个C++项目,并进入cppdemo目录中:

    mkdir ~/data/yx/cpp/cppdemo && cd ~/data/yx/cpp/cppdemo
    

    vi是打开文件,创建是vim

    vi hello.cpp
    
    #include   
    
    int main()
    {
    	printf("hello, World!\n");
    	system("pause");
    	return 0;
    }
    

    4. 运行
    用g++编辑器编译,生成可执行文件 hello

    g++ hello.cpp -o hello
    

    注: -o 后面的hello是生成的存储输出内容的文件名

    执行可执行文件(即打开hello)

    ./hello
    
  • cpp配置Onnxruntime
    参考: https://blog.csdn.net/Fenplan/article/details/116742180

  1. 安装python3(安装则跳过)

    apt-get install python3
    
  2. 安装pip3(安装则跳过)

    apt-get install python3-pip
    pip3 install --upgrade pip
    
  3. 安装依赖

    pip3 install --upgrade setuptools
    pip3 install --upgrade wheel
    pip3 install numpy
    
  4. 安装cmake

    sudo apt-get install cmake
    
  5. 下载onnxruntime(建议按照官方文档直接clone,不要自己到github上下载,不然运行过程中会报找不到某个文件的错误)

    ~/data/yx/cpp$ sudo git clone --recursive https://github.com/Microsoft/onnxruntime
    

    报错1:

    gnutls_handshake() failed: The TLS connection was non-properly terminated.
    

    解决:

    sudo git config --global  --unset https.https://github.com.proxy 
    sudo git config --global  --unset http.https://github.com.proxy 
    
  6. 安装onnxruntime

    cd onnxruntime 
    ./build.sh --config RelWithDebInfo --build_wheel --update --build
    

你可能感兴趣的:(visual,studio,windows,ubuntu)