需要区分release版本和debug版本
0、opencv配置
可以参考(49条消息) 如何在VS2019中配置OpenCV(C++)?_vs2019配置opencv_CV技术指南的博客-CSDN博客
Start Locally | PyTorchhttps://pytorch.org/get-started/locally/https://download.pytorch.org/libtorch/cu113/libtorch-win-shared-with-deps-1.10.0%2Bcu113.zip
Libtorch的介绍与使用方法_脆皮茄条的博客-CSDN博客_libtorchhttps://blog.csdn.net/weixin_43917589/article/details/124509964?ops_request_misc=&request_id=&biz_id=102&utm_term=libtorch&utm_medium=distribute.pc_search_result.none-task-blog-2~all~sobaiduweb~default-0-124509964.nonecase&spm=1018.2226.3001.4187(49条消息) win10系统上LibTorch的安装和使用(cuda10.1版本)_*Major*的博客-CSDN博客_win10安装libtorch
https://blog.csdn.net/qq_41375318/article/details/110556350?spm=1001.2101.3001.6650.4&utm_medium=distribute.pc_relevant.none-task-blog-2~default~CTRLIST~Rate-4-110556350-blog-114679263.pc_relevant_default&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2~default~CTRLIST~Rate-4-110556350-blog-114679263.pc_relevant_default&utm_relevant_index=9
trt配置:(需要先安装vs在安装cuda)
1、解压压缩包,放到合适的路径下
2、设置环境变量,右键我的电脑->属性->高级系统设置->高级中的环境变量->点击系统变量中的Path->添加路径:libtorch/bin和libtorch/lib,opencv的目录
3、配置属性调试加入环境
PATH=G:\Program Files (x86)\libtorch-win-shared-with-deps-1.10.0+cu113\libtorch\lib;%PATH%
在VC++包含目录加入:
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.3\include
G:\Program Files %28x86%29\libtorch-win-shared-with-deps-1.10.0+cu113\libtorch\include\torch
G:\Program Files %28x86%29\opencv\build\include
G:\Program Files %28x86%29\opencv\build\x64\vc15\lib
在VC++库目录加入:
G:\Program Files %28x86%29\opencv\build\x64\vc15\lib
G:\Program Files %28x86%29\libtorch-win-shared-with-deps-1.10.0+cu113\libtorch\lib
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.3\lib\x64
4、在C/C++常规的附加包含目录加入
G:\Program Files %28x86%29\libtorch-win-shared-with-deps-1.10.0+cu113\libtorch\include\torch\csrc\api\include
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.3\include
G:\Program Files %28x86%29\libtorch-win-shared-with-deps-1.10.0+cu113\libtorch\include
预处理器后加入NOMINMAX,命令行加入/INCLUDE:?warp_size@cuda@at@@YAHXZ
5、链接器输入中加入附加依赖项
opencv_world455.lib
opencv_world455d.lib
torch.lib
torch_cuda.lib
caffe2_detectron_ops_gpu.lib
caffe2_module_test_dynamic.lib
torch_cpu.lib
c10_cuda.lib
caffe2_nvrtc.lib
mkldnn.lib
c10.lib
dnnl.lib
libprotoc.lib
libprotobuf.lib
libprotobuf-lite.lib
fbgemm.lib
asmjit.lib
cpuinfo.lib
clog.lib
命令行加入:/INCLUDE:"?ignore_this_library_placeholder@@YAHXZ"
6、测试是否成功
#include<iostream>
#include<torch/script.h>
#include <torch/torch.h> # cuda相关函数头文件
#include<memory>
int main()
{
std::cout << "cuda::is_available():" << torch::cuda::is_available() << std::endl;
system("pause");
}