PyTorch实战:从基础构建到高级应用
1. 使用libTorch构建C++程序
首先,我们要使用 unzip 命令解压ZIP文件,这会创建一个新的 libtorch 目录。接着,创建一个名为 helloworld 的目录,并在其中添加一个最小化的 CMakeLists.txt 文件,用于构建可执行文件。
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
project(helloworld)
find_package(Torch REQUIRED)
add_executable(helloworld helloworld.cpp)
target_link_libraries(helloworld "${TORCH_LIBRARIES}")
set_property(TARGET helloworld PROPERTY CXX_STANDARD 11)
helloworld.cpp 文件内容如下:
#include <torch/torch.h>
#include <iostream>
int main() {
torch::Tensor tensor = torch::ones({2, 2});
std::cout << tensor << std::endl;
}
超级会员免费看
订阅专栏 解锁全文
1303

被折叠的 条评论
为什么被折叠?



