ubuntu20.04 使用libtorch
2022/1/25 7:07:40
本文主要是介绍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 使用libtorch的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-06-26小白家庭 nas 搭建方案-icode9专业技术文章分享
- 2024-06-23AI大模型企业应用实战(14)-langchain的Embedding
- 2024-06-23AI大模型企业应用实战(15)-langchain核心组件
- 2024-06-23AI大模型企业应用实战(16)-langchain核心组件
- 2024-06-23AI 大模型企业应用实战(06)-初识LangChain
- 2024-06-19EntBot.ai: AI Website Chatbot for Product Guides and Development Doc
- 2024-06-17zero-shot-learning-definition-examples-comparison
- 2024-06-06Package Easy(基于 NSIS 的打包exe安装包工具)使用方法-icode9专业技术文章分享
- 2024-06-06基于 casdoor 的 ELK 开源登录认证解决方案: elk-auth-casdoor-icode9专业技术文章分享
- 2024-05-29Elasticsearch慢查询日志配置