LibTorch在windows下编译

网友投稿 726 2022-11-23

LibTorch在windows下编译

LibTorch在windows下编译

文章目录

​​准备工作​​​​文件目录​​​​进行编译​​

准备工作

cmakelibTorch

文件目录

进行编译

CMakeLists.txt

cmake_minimum_required(VERSION 3.12 FATAL_ERROR)project(example-app)find_package(Torch REQUIRED)find_package(OpenCV REQUIRED)if(NOT Torch_FOUND) message(FATAL_ERROR "Pytorch Not Found!")endif(NOT Torch_FOUND)message(STATUS "Pytorch status:")message(STATUS " libraries: ${TORCH_LIBRARIES}")message(STATUS "OpenCV library status:")message(STATUS " version: ${OpenCV_VERSION}")message(STATUS " libraries: ${OpenCV_LIBS}")message(STATUS " include path: ${OpenCV_INCLUDE_DIRS}")add_executable(example-app example.cpp)target_link_libraries(example-app ${TORCH_LIBRARIES} ${OpenCV_LIBS})set_property(TARGET example-app PROPERTY CXX_STANDARD 11)

example.cpp

#include // One-stop header.#include #include int main(int argc, const char* argv[]) { if (argc != 2) { std::cerr << "usage: example-app \n"; return -1; } // Deserialize the ScriptModule from a file using torch::jit::load(). torch::jit::script::Module module = torch::jit::load(argv[1]); assert(module != nullptr); std::cout << "ok";}

设置libTorch和opencv的根目录

cmake -DCMAKE_PREFIX_PATH=D:\MyWorkSpace\Lib\opencv\build\x64\vc15\lib;D:\MyWorkSpace\Lib\libtorch -DCMAKE_BUILD_TYPE=Release -G “Visual Studio 15 Win64” …

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:js字符串常用方法
下一篇:基于gdal的空间缓冲区分析(python)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~