生活随笔
收集整理的這篇文章主要介紹了
关于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上別人的報錯,我當時沒有把自己的報錯截圖下來,但問題是一樣的)
-- The C compiler identification is GNU 7.3.-- The CXX compiler identification is GNU 7.3.-- 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 - doneCMake Error at CMakeLists.txt: (find_package):By not providing "FindTorch.cmake" in CMAKE_MODULE_PATH this project hasasked CMake to find a package configuration file provided by "Torch", butCMake did not find one.Could not find a package configuration file provided by "Torch" with any ofthe following names:TorchConfig.cmaketorch-config.cmakeAdd 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 beeninstalled.-- Configuring incomplete, errors occurred!
原因:它無法找到TorchConfig.cmake和torch-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的方式,不然會報錯.
總結
以上是生活随笔為你收集整理的关于windows10用c++部署libtorch过程中遇到的一些问题的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。