关于windows10用c++部署libtorch过程中遇到的一些问题

  • libtorch1.0
  • vs2017
  • CMake3.14
  • windows10
  • 无cuda

用c++调用pytorch模型官网上面有详细教程,也有很多博客,可以参考以下链接:https://blog.csdn.net/dou3516/article/details/82912480

以及:https://zhuanlan.zhihu.com/p/55292836

在操作的过程中,主要遇到三个比较大的问题:

问题一:cmake编译时以及找不到torch和opencv相关的cmake文件(以下代码是复制的stackoverflow上别人的报错,我当时没有把自己的报错截图下来,但问题是一样的)

-- The C compiler identification is GNU 7.3.0
-- The CXX compiler identification is GNU 7.3.0
-- Could not determine Eclipse version, assuming at least 3.6 (Helios). Adjust CMAKE_ECLIPSE_VERSION if this is wrong.
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error at CMakeLists.txt:10 (find_package):
  By not providing "FindTorch.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "Torch", but
  CMake did not find one.

  Could not find a package configuration file provided by "Torch" with any of
  the following names:

    TorchConfig.cmake
    torch-config.cmake

  Add the installation prefix of "Torch" to CMAKE_PREFIX_PATH or set
  "Torch_DIR" to a directory containing one of the above files.  If "Torch"
  provides a separate development package or SDK, be sure it has been
  installed.


-- Configuring incomplete, errors occurred!

原因:它无法找到TorchConfig.cmaketorch-config.cmake文件

解决方法:通过编辑CMakeLists.txt解决,将libtorch文件中的path/libtorch/share/cmake/Torch 加到路径中去,如图所示

 

以及将opencv安装路径的build添加到系统环境变量中去:(变量名为如图所示,地址根据个人地址修改)

 

问题二:编译成功后,运行.cpp显示程序无法启动ALL_BUILD 拒绝访问

解决方法:CMake编译成功后会生成三个工程文件,分别是ALL_BUILD,工程本身文件(我的叫lenet),以及ZERO_CHECK,将ALL_BUILD和ZERO_CHECK在工程文件中移除即可以解决.

问题三:找不到dll文件,如图:

解决方法:将路径为\path\libtorch\lib中对应的torch.dll等对应缺失的文件复制到路径为\build\Debug和\build\Release中去即可解决.

注:用vs运行.cpp时要讲解决方案配置改为Release x64的方式,不然会报错.

 

转载于:https://www.cnblogs.com/yeshengCqupt/p/10448476.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值