安装流程
1、下载libtorch
官方地址:https://pytorch.org/
首先在官网下载,或者用指令下载:下载自己要的对应版本
wget https://download.pytorch.org/libtorch/cpu/libtorch-cxx11-abi-shared-with-deps-1.7.1%2Bcpu.zip
2、解压
unzip libtorch-cxx11-abi-shared-with-deps-1.7.1+cpu
3、编写测试工程
先编写一个测试工程test_libtorch
CMakeLists.txt
cmake_minimum_required(VERSION 2.8 FATAL_ERROR) project(test-libtorch) set(Torch_DIR ~/libtorch/share/cmake/Torch) #你解压的libtorch的绝对路径 find_package(Torch REQUIRED) set(CMAKE_CXX_FLAGS "${CAMKE_CXX_FLAGS} ${TORCH_CXX_FLAGS}") #main.cpp exe add_executable(test-libtorch test.cpp) #link libtorch .a .so target_link_libraries(test-libtorch "${TORCH_LIBRARIES}") # set_property(TARGET test-libtorch PROPERTY CXX_STANDARD 14)
test.cpp
#include<torch/torch.h> #include<iostream> //using namespace std; int main(){ torch::Tensor tensor = torch::eye(3); std::cout << tensor << std::endl; }
4、编译
mkdir build cd build cmake .. make ./test-libtorch
参考博客
https://blog.csdn.net/qq_37644877/article/details/112478858