0
点赞
收藏
分享

微信扫一扫

LibTorch在windows下编译


文章目录

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

准备工作

  • cmake
  • libTorch

文件目录

LibTorch在windows下编译_pytorch

进行编译

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 <torch/script.h> // One-stop header.
#include <iostream>
#include <memory>

int main(int argc, const char* argv[]) {
if (argc != 2) {
std::cerr << "usage: example-app <path-to-exported-script-module>\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” …

LibTorch在windows下编译_文件目录_02


举报

相关推荐

0 条评论