日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > c/c++ >内容正文

c/c++

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

發布時間:2024/9/27 c/c++ 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 关于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 - done
  • CMake Error at CMakeLists.txt: (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.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过程中遇到的一些问题的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。