0
点赞
收藏
分享

微信扫一扫

Ubuntu16.04安装Libtorch


安装流程

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

Ubuntu16.04安装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

Ubuntu16.04安装Libtorch_深度学习_02


举报

相关推荐

0 条评论