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

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

用c++调用pytorch模型官网上面有详细教程,也有很多博客,可以参考以下链接:pytorch怎么使用c++调用部署模型?_豆芽菜-CSDN博客_pytorch用c++

以及:Pytorch的C++前端(libtorch)在Windows下的预测 - 知乎

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

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

 
  1. -- The C compiler identification is GNU 7.3.
  2. -- The CXX compiler identification is GNU 7.3.
  3. -- Could not determine Eclipse version, assuming at least 3.6 (Helios). Adjust CMAKE_ECLIPSE_VERSION if this is wrong.
  4. -- Check for working C compiler: /usr/bin/cc
  5. -- Check for working C compiler: /usr/bin/cc -- works
  6. -- Detecting C compiler ABI info
  7. -- Detecting C compiler ABI info - done
  8. -- Detecting C compile features
  9. -- Detecting C compile features - done
  10. -- Check for working CXX compiler: /usr/bin/c++
  11. -- Check for working CXX compiler: /usr/bin/c++ -- works
  12. -- Detecting CXX compiler ABI info
  13. -- Detecting CXX compiler ABI info - done
  14. -- Detecting CXX compile features
  15. -- Detecting CXX compile features - done
  16. CMake Error at CMakeLists.txt: (find_package):
  17. By not providing "FindTorch.cmake" in CMAKE_MODULE_PATH this project has
  18. asked CMake to find a package configuration file provided by "Torch", but
  19. CMake did not find one.
  20. Could not find a package configuration file provided by "Torch" with any of
  21. the following names:
  22. TorchConfig.cmake
  23. torch-config.cmake
  24. Add the installation prefix of "Torch" to CMAKE_PREFIX_PATH or set
  25. "Torch_DIR" to a directory containing one of the above files. If "Torch"
  26. provides a separate development package or SDK, be sure it has been
  27. installed.
  28. -- 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的方式,不然会报错.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值