轉載:https://www.jianshu.com/p/542231f43207
libTorch下載
pytroch為windows端提供了2個版本的預編譯好的libTorch動態鏈接庫
- Debug
-
Release
image.png
測試環境
- win10 64bit
- vs2017
- libTorch
配置過程
以Debug版本的libTorch為例
- 添加include路徑
- 添加鏈接庫lib路徑
- 添加lib名稱
- 添加環境變量

image.png

image.png

image.png
c10.lib
caffe2.lib
caffe2_detectron_ops.lib
caffe2_module_test_dynamic.lib
clog.lib
cpuinfo.lib
foxi_dummy.lib
foxi_loader.lib
libprotobuf-lited.lib
libprotobufd.lib
libprotocd.lib
onnx.lib
onnxifi_dummy.lib
onnxifi_loader.lib
onnx_proto.lib
torch.lib
測試代碼
- demo1
#include<iostream> #include<torch/script.h> int main() { torch::Tensor t1 = torch::tensor({ 10,1,2 }); std::cout << t1[0] << std::endl; system("pause"); }

image.png
- demo2
2個Tensor計算矩陣乘法
#include<iostream> #include<torch/script.h> int main() { auto t1 = torch::tensor({ 1,2,3,4,5,6,7,8,9 }).reshape({ 3,3 }); auto t2 = torch::tensor({ 1,0,2,6,1,1,5,3,2 }).reshape({ 3,3 }); auto t3 = t1.mul(t2); std::cout << t3 << std::endl; system("pause"); }

image.png
作者:俠之大者_7d3f
鏈接:https://www.jianshu.com/p/542231f43207
來源:簡書
著作權歸作者所有。商業轉載請聯系作者獲得授權,非商業轉載請注明出處。