ubuntu20.04 使用libtorch
作者:互联网
一、官网下载文件
https://pytorch.org/get-started/locally/
选择下载Stable(1.10.1) C++ CPU(cxx 11 ABI)
解压.zip压缩包,将libtorch移动到存放第三方库的位置
二、使用
2.1 创建torch_ws文件夹,然后创建如下两文件
example-app.cpp
#include "torch/torch.h"
#include <iostream>
int main() {
torch::Tensor tensor = torch::rand({2, 3});
std::cout << tensor << std::endl;
}
CMakeLists.txt
cmake_minimum_required(VERSION 3.5)
project(test_pytorch)
set(CMAKE_CXX_STANDARD 14)
set(Torch_DIR /home/chenjian/Downloads/torch_ws/libtorch/share/cmake/Torch)
find_package(Torch REQUIRED)
add_executable(example-app example-app.cpp)
target_link_libraries(example-app "${TORCH_LIBRARIES}")
标签:ubuntu20.04,Torch,app,torch,libtorch,set,使用,example 来源: https://www.cnblogs.com/chenjian688/p/15839262.html